a month ago - last edited a month ago by JackLacava
Hi everyone,
Thanks in advance for helping.
I am new to tree views and trying to get a simple hierarchy (from the account dimension) to show as a tree view. Part of the structure is shown in the screenshot below:
I'm using the following Dashboard Data Set Business Rule that I run using a data adapter linked to my tree view:
If args.DataSetName.XFEqualsIgnoreCase("TreeView")
'Declare the account dimPK
Dim DimPk As DimPk = BRApi.Finance.Dim.GetDimPk(si, "actAccount")
'Declare the parent ID + member
Dim parentMbrId As Integer = BRApi.Finance.Members.GetMemberId(si, dimTypeId.Account, "CF_000000")
Dim parentMbr As Member = BRApi.Finance.Members.GetMember(si, dimTypeId.Account, parentMbrId)
'Declare the child list of the parent
Dim childList As List(Of Member) = BRApi.Finance.Members.GetChildren(si, DimPk, ParentMbrId)
'Dim the new XFTreeItem List + properties
Dim treeChildren As New List(Of XFTreeItem)
Dim textColour As String = XFColors.Black.Name
Dim imageSource As String = XFImageFileSourceType.ClientImage
Dim imageName As String = XFClientImageTypes.StatusGrayBall.Name
Dim isBold As Boolean = False
Dim isEnabled As Boolean = True
Dim isSelected As Boolean = False
Dim isExpanded As Boolean = True
'Loop through the children
For Each child As Member In childList
treeChildren.Add( _
New XFTreeItem( child.Name, child.NameAndDescription, textColour, _
isBold, isEnabled, isSelected, isExpanded, imageSource, imageName, _
child.Name, Nothing))
Next child
'Add the children to the parent
Dim treeCollection As New XFTreeItemCollection
treeCollection.TreeItems.Add( _
New XFTreeItem( parentMbr.Name, parentMbr.NameAndDescription, textColour, _
isBold, isEnabled, isSelected, isExpanded, imageSource, imageName, _
parentMbr.name, treeChildren))
Return treeCollection.CreateDataSet(si)
End If
I know the code is far from done. However, the output is currently looking like this:
Can someone help me with getting the next 'layers' of the hierarchy in place? Under CF_100000 etc?
Any help is appreciated!
Thanks a lot.
Floris
a month ago - last edited a month ago
I like to use recursive functions for things like this. Not sure if there is a more out of the box way as I haven't done a lot with treeviews.
I asked AI to turn your code into a recursive function. No idea if it works but it might set you on the path.
Sub BuildTree(ByVal si As SessionInfo, ByVal DimPk As DimPk, ByVal parentMbrId As Integer, ByVal parentMbrName As String, ByVal parentMbrDescription As String, ByVal textColour As String, ByVal imageSource As String, ByVal imageName As String, ByVal isBold As Boolean, ByVal isEnabled As Boolean, ByVal isSelected As Boolean, ByVal isExpanded As Boolean, ByVal treeCollection As XFTreeItemCollection)
'Declare the child list of the parent
Dim childList As List(Of Member) = BRApi.Finance.Members.GetChildren(si, DimPk, parentMbrId)
'Dim the new XFTreeItem List
Dim treeChildren As New List(Of XFTreeItem)()
'Loop through the children
For Each child As Member In childList
' Recursively build children of children
Dim childTreeCollection As New XFTreeItemCollection()
BuildTree(si, DimPk, child.Id, child.Name, child.NameAndDescription, textColour, imageSource, imageName, isBold, isEnabled, isSelected, isExpanded, childTreeCollection)
' Create XFTreeItem for current child and add children to it
Dim childTreeItem As New XFTreeItem(child.Name, child.NameAndDescription, textColour, isBold, isEnabled, isSelected, isExpanded, imageSource, imageName, child.Name, childTreeCollection)
treeChildren.Add(childTreeItem)
Next
' Add the children to the parent
Dim parentTreeItem As New XFTreeItem(parentMbrName, parentMbrDescription, textColour, isBold, isEnabled, isSelected, isExpanded, imageSource, imageName, parentMbrName, treeChildren)
treeCollection.TreeItems.Add(parentTreeItem)
End Sub
' Usage:
Dim DimPk As DimPk = BRApi.Finance.Dim.GetDimPk(si, "actAccount")
Dim parentMbrId As Integer = BRApi.Finance.Members.GetMemberId(si, dimTypeId.Account, "CF_000000")
Dim parentMbr As Member = BRApi.Finance.Members.GetMember(si, dimTypeId.Account, parentMbrId)
Dim textColour As String = XFColors.Black.Name
Dim imageSource As String = XFImageFileSourceType.ClientImage
Dim imageName As String = XFClientImageTypes.StatusGrayBall.Name
Dim isBold As Boolean = False
Dim isEnabled As Boolean = True
Dim isSelected As Boolean = False
Dim isExpanded As Boolean = True
Dim treeCollection As New XFTreeItemCollection()
BuildTree(si, DimPk, parentMbrId, parentMbr.Name, parentMbr.NameAndDescription, textColour, imageSource, imageName, isBold, isEnabled, isSelected, isExpanded, treeCollection)
a month ago - last edited a month ago
Hi @FlorisvdPoel given your use case, you might want to consider using one of the no-code approaches to achieve the same e.g. using the Member Tree component with a Member Dialog parameter type?
I wrote a blog on this here that you might find useful. Otherwise you will need a recursive function to iterate through each level in your hierarchy as per advice from @DanielWillis
a month ago
Hi Sameburn, Daniel,
Thanks for your responses.
I indeed got the initial code from your blog @sameburn. The reason I'm not going for the no-code solution is mainly because I have an external (mapping) table that maps certain accounts to other accounts within the structure I would like to present.
So, after I get the above structure in the tree view, I want to show the mapped accounts under the already presented members.
I will try the recursive function from @DanielWillis!
Thanks a lot.
Floris
a month ago
@FlorisvdPoel - Did you try to print the Members inside for loop and see what the members are it is printing. Since you are getting the children of CF_000000 and I guess it is returning correctly.
Dim childList As List(Of Member) = BRApi.Finance.Members.GetChildren(si, DimPk, ParentMbrId)