Forum Discussion

jvonallmen's avatar
jvonallmen
New Contributor III
4 years ago

How can I use a Business Rule to sort a Member List in alphabetical order?

 

 

Namespace OneStream.BusinessRule.Finance.XFR_MemberListAlphabetical
	Public Class MainClass
		'---------------------------------------------------------------------------------------------------
		'Reference Code: 	XFR_MemberListAlphabetical
		'
		'Description:		Use a business rule to sort a member list in Alphabetical order
		'
		'Usage:				This will put a member list of a dimension in Alphabetical order. 
		'					Use the following on the cube view:
		'                      E#Member.[Name of Business Rule, Name of List in Business Rule]
		'					e.g. E#Root.[XFR_MemberListAlphabetical, EntityAlphabetical]
		'
		'Created By:		Robert Powers (put in XF Ref by John Von Allmen)
		'
		'Date Created:		5-24-2013
		'---------------------------------------------------------------------------------------------------	
		Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, _
		                     ByVal api As FinanceRulesApi, ByVal args As FinanceRulesArgs) As Object
			Try

				'This will put a member list of a dimension in Alphabetical order. 
				'Use the following on the cube view:
				'        E#Member.[Name of Business Rule, Name of List in Business Rule]
				'     e.g. E#Root.[XFR_MemberListAlphabetical, EntityAlphabetical]								
				Dim Memberlistname As String = "Ent_Sort"
				Dim MemberListstart As String = "E#[Total GolfStream].base"
			
				Select Case api.FunctionType      
					Case Is = FinanceFunctionType.MemberList
			            If args.MemberListArgs.MemberListName = Memberlistname Then
		                    Dim objMemberListHeader = New MemberListHeader( _
															args.MemberListArgs.MemberListName)
		                    
		                    'Read the members
		                    Dim objMemberInfos As List(Of MemberInfo) = api.Members.GetMembersUsingFilter( _
                            							args.MemberListArgs.DimPk, MemberListstart, Nothing)

		                    'Sort the members
		                    Dim objMembers As List(Of Member) = Nothing
		                    If Not objMemberInfos Is Nothing Then
		                    	objMembers = (From memberInfo In objMemberInfos _
								              Order By memberInfo.Member.Name Ascending _
											  Select memberInfo.Member).ToList()
		                    End If
		                    
		                    'Return
		                    Return New MemberList(objMemberListHeader, objMembers)
			            End If
				End Select
				Return Nothing
				
			Catch ex As Exception
				Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
			End Try
		End Function
	End Class
End Namespace

 

 

  • amvillaruel's avatar
    amvillaruel
    New Contributor II

    Hello, do we have an example where this is used in account dimension? I tried it but it would only show the parent account. For example, I use A#ParentAccount.Base as the Memberliststart, the cube view will only show the ParentAccount and not the base members.

    I then tried to switch the dimension to Entity in the cube view and also the Memberliststart to E#TopEntity.Base, and it works just fine so I'm wondering if this only works for Entity dimension.

    • amvillaruel's avatar
      amvillaruel
      New Contributor II

      Hi All,

      I was able to make it work for the Account Dimension by using the Finance Metadata function called GetMembersUsingFilter with this syntax:
      BRApi.Finance.Metadata.GetMembersUsingFilter(si, dimensionName, memberFilter, removeDuplicates, dimDisplayOptions, memberDisplayOptions)

      The above worked better than the Members function with syntax:

      api.Members.GetMembersUsingFilter(args.MemberListArgs.DimPk, MemberListstart, Nothing).

      Hope this helps!