Forum Discussion

Krishna's avatar
Krishna
Valued Contributor
3 years ago

Delete Multiple Members using Extender Rule

All - The below extender rule will be able to delete multiple member from Parent Hierarchy. 

1. Provide the Dimension Name & Top Parent Name in the Hierarchy - See highlighted in Red.

2. I want to make a point here the While Count > 3 because the it takes the current parent and other member ENtityDefault1 & None. Since we will not be able to delete it so it should be 3 or loop will be infinite. 

3. You can use as an input Variable for Dimension and Top Parent and attach to the dashboard but this is a good starting point.  


Dim dimensionPK As DimPk = BRApi.Finance.Dim.GetDimPk(si,"Dimension")
Dim nValue As Integer = BRApi.Finance.Members.GetMemberId(si, dimensionPK.DimTypeId,"TopParentName")

Dim objList1 As List(Of Member) = BRApi.Finance.Members.GetAllMembers(si,dimensionPK,nValue)
Dim objList2 As List(Of Member) = BRApi.Finance.Members.GetBaseMembers(si,dimensionPK,nValue)

Dim mbrct As Integer = objList1.Count

While mbrct > 3

For Each mbrbe As Member In objList2

If mbrbe.Name <> "None" Then
BRApi.Finance.MemberAdmin.RemoveMember(si, dimensionPK, mbrbe.MemberPk)

End If
Next
objList1 = BRApi.Finance.Members.GetAllMembers(si,dimensionPK,nValue)
objList2 = BRApi.Finance.Members.GetBaseMembers(si,dimensionPK,nValue)
mbrct = objList1.Count

End While

10 Replies

  • JackLacava's avatar
    JackLacava
    Community Manager

    Hey Krishna, thanks so much for the contribution!

    As a quick tip for the future, you can get better formatting for code by expanding the toolbar

    and then selecting the Code option

    On the code itself, I suspect there might be a way to do this that would make fewer calls and wouldn't rely on checking the number of members left...

    • Krishna's avatar
      Krishna
      Valued Contributor

      Thanks Jack for the feedback. I will make sure next time.

  • bhandelman's avatar
    bhandelman
    New Contributor III

    I built a similar BR recently and it is taking about ten seconds to delete each member.  Is that normal? I am using a Delete instead of a Remove.

    • Krishna's avatar
      Krishna
      Valued Contributor

      It should not take 10's. Did you try with remove option?

      • bhandelman's avatar
        bhandelman
        New Contributor III

        I did not try Remove because I assumed it would just orphan the member. I need to really Delete the member because I am deleting the entire dimension.  I am adding dimensions and then deleting them until i get everything right. Do you know if Remove does the same thing as Delete or does Remove orphan the member?

  • MarkBird's avatar
    MarkBird
    Contributor III

    Hi all

    I'm using the BRApi.Finance.MemberAdmin.RemoveMember to remove a UD4 member which works well.

    I was wondering if you had any suggestions on what the best way to check on whether there is information stored against the member is?

    i.e. is there a built in function or do I need to do a get data cell formula

    Thanks,

    Mark

    • MarkBird's avatar
      MarkBird
      Contributor III

      I came up with the following solution, which seemed to be the simplest:

      Dim d As [Dim] = BRApi.Finance.Dim.GetDim(si, "UDDimension")
      Dim m As Member = BRApi.Finance.Members.GetMember(si, d.DimPk.DimTypeId, xfRow.OriginalDataRow("MemberName"))
      Dim sql As String = "SELECT TOP 1 * FROM vDataRecordAll Where UD4Id = '" & m.MemberId & "'"
      Dim dt As DataTable = BRApi.Database.ExecuteSql(dbConn, sql, False)
      
      If dt.Rows.Count <> 1 Then
      	BRApi.Finance.MemberAdmin.RemoveMember(si, d.DimPk, m.MemberPk)
      End If

       

      • JackLacava's avatar
        JackLacava
        Community Manager

        I think that should do, although in theory you might want to check one of the Stage views too, on the target columns.