Forum Discussion
Russell
3 days agoNew Contributor III
Something like this. I have not tested this and the RemoveRelationships (line 36) last argument of "True" will create orphans if the member does not have another parent.
' Define dimension and parent rollup as parameters or hardcode here
Dim EntityDimPK As DimPk = BRApi.Finance.Dim.GetDimPk(si, "MgmtEntity")
Dim dimTypeId As Integer = EntityDimPK.DimTypeId
Dim RollupName As String = "Global_excl_YS"
' FIX: use the DimPk-based overload (your original used dimtype.Entity.Id)
Dim RollupMember As Member = BRApi.Finance.Members.GetMember(si, dimTypeId, RollupName)
' Get all direct children of the rollup
Dim Children As List(Of Member) = BRApi.Finance.Members.GetChildren(si, EntityDimPK, RollupMember.MemberId, Nothing)
Dim RemovedEntities As New List(Of String)
Dim RelToRemove As New List(Of RelationshipPk)
For Each ChildMember As Member In Children
Dim ChildName As String = ChildMember.Name
Dim ChildDesc As String = If(ChildMember.Description, String.Empty)
' Check if base (no children)
Dim HasChildren As Boolean = BRApi.Finance.Members.HasChildren(si, EntityDimPK, ChildMember.MemberId, Nothing)
If Not HasChildren Then
' Check if "YS" in name or description (case-insensitive)
Dim nameHas As Boolean = ChildName.IndexOf("YS", StringComparison.OrdinalIgnoreCase) >= 0
Dim descHas As Boolean = ChildDesc.IndexOf("YS", StringComparison.OrdinalIgnoreCase) >= 0
If nameHas Or descHas Then
RelToRemove.Add(New RelationshipPk(dimTypeId,RollupMember.MemberId,ChildMember.MemberId))
RemovedEntities.Add(ChildName)
End If
End If
Next
If RemovedEntities.Count = 0 Then
Return "No base children with 'YS' found under " & RollupName
Else
BRApi.Finance.MemberAdmin.RemoveRelationships(si, EntityDimPK, RelToRemove, True)
Return "Removed from " & RollupName & ": " & String.Join(", ", RemovedEntities)
End If
Related Content
- 2 years ago
- 2 years ago