Forum Discussion
Hello,
Usually I would not recommend relying on the order of child members in the hierarchy. The order of member is often a forgotten admin task, and these may easily be moved around in an unexpected way if the application has some kind of metadata automation in the future.
Back to the question though: If you want to do a [ Get N-th Child ] where N=1,2,3 etc then you could use an XFBR to do this.
Example in GolfStream , CorpAccounts dimension:
16999 - Net PP&E
16099 - Machinery
16199 - Land
16100 - Land at Cost
16105 - Land Depreciation
Let's say we wanted to get the 2nd child of 16999, and then get the children of that. ( which are A#16100,A#16105)
Then you would do this in the row member filter in your CubeView or QuickView
A#XFBR(CubeViewLists,GetNthChild,Parent=[16999],DimName=[CorpAccounts],N=2).Children
Output:
Below is the code that you would put into a Dashboard XFBR business rule.
Don't be put off by the code, every line except for the last line is doing error checking.
If args.FunctionName.XFEqualsIgnoreCase("GetNthChild") Then
' -- Example use in GolfStream app
' -- A#XFBR(CubeViewLists,GetNthChild,Parent=[16999],DimName=[CorpAccounts],N=2).Children
Dim strParent As String = args.NameValuePairs.GetValueOrEmpty("Parent")
Dim strDimName As String = args.NameValuePairs.GetValueOrEmpty("DimName")
Dim strN As String = args.NameValuePairs.GetValueOrEmpty("N")
If String.IsNullOrEmpty(strParent) _
OrElse String.IsNullOrEmpty(strDimName) _
OrElse String.IsNullOrEmpty(strN) Then
Throw New XFException(si, "Error with arguments supplied to GetNthChild", _
"Usage: XFBR(CubeViewLists,GetNthChild,Parent=[Parent Member Name],DimName=[Dimension Name],N=[Position 1,2,3 etc])")
End If
Dim myDimPk As DimPk = BRApi.Finance.Dim.GetDimPk(si, strDimName)
If myDimPk Is Nothing Then
Throw New XFException(si, "Error with arguments supplied to GetNthChild", _
"Invalid dimension Name:" & strDimName)
End If
Dim iRequestedPosition As Integer
If Not Integer.TryParse(strN,iRequestedPosition) _
OrElse iRequestedPosition=0 Then
Throw New XFException(si, "Error with arguments supplied to GetNthChild", _
"Parameter N must be a non-zero integer")
End If
Dim iParentId As Integer = BRApi.Finance.Members.GetMemberId(si, myDimPk.DimTypeId, strParent)
If iParentId.Equals(DimConstants.Unknown) Then
Throw New XFException(si, "Error with arguments supplied to GetNthChild", _
"Supplied Parent Name is invalid:" & strParent)
End If
Dim lstMbrs As List(Of Member) = BRApi.Finance.Members.GetChildren(si, myDimPk, iParentId)
If lstMbrs.Count = 0 Then
Throw New XFException(si, "Specified parent has no child members in this dimension", _
"Parent Name:" & strParent)
End If
If lstMbrs.Count < iRequestedPosition Then
Throw New XFException(si, _
"Specified parent has less children than the position requested","Parent Name:" _
& strParent & ", NumChildren=" & lstMbrs.Count)
End If
Return lstMbrs(iRequestedPosition-1).Name
End If
Related Content
- 3 months ago
- 8 months ago
- 2 years ago