Forum Discussion

Vigneshwar's avatar
Vigneshwar
New Contributor
2 years ago

Sorting members.

How to sort members from smallest to largest and vice versa based on amount using business rules??

  • ChristianW's avatar
    ChristianW
    Valued Contributor

    I assume you like to do it in a dynamic list for cubeviews. This code works:

    If args.MemberListArgs.MemberListName.XFEqualsIgnoreCase("Sorted") Then
    	
    	Dim yourScript As String = args.MemberListArgs.NameValuePairs("Script")
    	Dim yourDimTypeName As String = args.MemberListArgs.NameValuePairs("DimType")
    	Dim yourParent As String = args.MemberListArgs.NameValuePairs("Parent")
    	
    	Dim yourDimTyp As DimType = DimType.GetItem(yourDimTypeName)
    	
    	Dim dataBufferOfScript As DataBuffer = api.Data.GetDataBufferUsingFormula($"FilterMembers({yourScript}, {yourDimTyp.Abbrev}#{yourParent}.base)")
    	
    	Dim listOfDataBufferCells As List(Of DataBufferCell) = dataBufferOfScript.DataBufferCells.Values.ToList()
    
    '	listOfDataBufferCells = listOfDataBufferCells.OrderByDescending(Function(x) x.CellAmount).ToList()
    	listOfDataBufferCells = listOfDataBufferCells.OrderBy(Function(x) x.CellAmount).ToList()
    	Dim listOfUd1 As List(Of MemberInfo) = listOfDataBufferCells.Select(Function(x) New MemberInfo(api.Members.GetMember(DimTypeId.UD1, x.DataBufferCellPk.UD1Id))).ToList()
    	
    	Dim objMemberListHeader As New MemberListHeader(args.MemberListArgs.MemberListName)
    	Dim objMemberList As New MemberList(objMemberListHeader, listOfUd1)
    	Return objMemberList							
    	
    End If
    

    in a cubeview you call it like this:

    UD1#Root.CustomMemberList(BRName=CustomLists, MemberListName=Sorted, script=[E#NAE:C#Local:S#Actual:T#2023M6:V#Periodic:A#99999:F#EndBalLoad:O#Top:I#Top:U2#REGTop:U3#PRDTop:U4#CSTTop:U5#None:U6#None:U7#UD7Top:U8#None],DimType=Ud1, Parent=CCTop)