Forum Discussion

carbon's avatar
carbon
New Contributor
22 days ago

Business Rule to Remove Base-Level Entities from a Parent Rollup Based on Keyword Match

Hi everyone,

I'm working on a Business Rule in OneStream and could use some guidance.

I’m trying to build a rule that targets a user-defined parent rollup within the Entity Dimension. The goal is to automatically remove the relationship between that rollup and any base-level child entities whose name or description contains a specific keyword — in this case, "YS".

Here’s what I’m aiming for:

  • The rule should accept a parent rollup name (e.g., Global_excl_YS)
  • It should loop through all children of that rollup
  • If a child is a base member and its name or description includes "YS", the rule should "remove the relationship"
  • Parent or intermediate rollups should remain untouched

I’m planning to implement this as an Extensibility Business Rule, but I’d love to hear if anyone has done something similar or has tips on best practices for metadata manipulation in this context.

Thanks in advance!



' Define dimension and parent rollup as parameters or hardcode here
                Dim EntityDimPK As DimPk = BRApi.Finance.Dim.GetDimPk(si, "MgmtEntity")
                Dim RollupName As String = "Global_excl_YS"
                Dim RollupMember As Member = BRApi.Finance.Members.GetMember(si, dimtype.Entity.Id, 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)
                For Each ChildMember As Member In Children
                    Dim ChildName As String = ChildMember.Name
                    Dim ChildDesc As String = If(ChildMember.Description, "")
                    ' 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
                        If ChildName.ToUpper().Contains("YS") Or ChildDesc.ToUpper().Contains("YS") Then
                            ' Remove Relationship
 
                        End If
                    End If
                Next
 
                If RemovedEntities.Count = 0 Then
                    Return "No base children with 'YS' found under " & RollupName
                Else
                    Return "Removed from " & RollupName & ": " & String.Join(", ", RemovedEntities)
                End If

 

1 Reply

  • Russell's avatar
    Russell
    New 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