Forum Discussion

MarkBird's avatar
MarkBird
Contributor III
2 years ago

ParentMemberId is always -1?

Hi

I have got a list of member info and trying to do a simple loop through the list to get the member and it's parent using the following code, however ParentMemberId is always coming back as -1.

Dim UD1DimPk As DimPk = BRApi.Finance.Dim.GetDimPk(si, "CostCentre")
Dim listMI As List(Of MemberInfo) = BRApi.Finance.Members.GetMembersUsingFilter(si, UD1DimPk, "U1#Root.TreeDescendants", False)

For Each item In listMI
	BRApi.ErrorLog.LogMessage(si, item.Member.Name & " | " & item.ParentMemberId)
Next

I've also tried to include DimDisplayOptions and MemberDisplayOptions using following but I have had no luck

Dim cubeID As Integer = BRApi.Finance.Cubes.GetCubeInfo(si, "MY_CUBE").Cube.CubeId
Dim scenarioID As Integer = ScenarioDimHelper.GetIdFromName(si, "Actual")
Dim dimDisplay As DimDisplayOptions = New DimDisplayOptions(cubeID, scenarioID)
Dim memberDisplay As MemberDisplayOptions = New MemberDisplayOptions(True, CultureInfo.CurrentCulture.Name, True, True, True, True, True, 0)
Dim UD1DimPk As DimPk = BRApi.Finance.Dim.GetDimPk(si, "CostCentre")

Dim listMI As List(Of MemberInfo) = BRApi.Finance.Members.GetMembersUsingFilter(si, UD1DimPk, "U1#Root.TreeDescendants", False, dimDisplay, memberDisplay)

For Each item In listMI
	BRApi.ErrorLog.LogMessage(si, item.Member.Name & " | " & item.ParentMemberId)
Next

What am I missing?

Mark

  • I suspect that GetMembersUsingFilter always returns a flat list of members, regardless of the filter expansion you use - hence, without parent IDs set.

    MemberInfo, as a class, can express parent-child relationships and indentation levels, but not all functions that produce MemberInfo objects will actually leverage such power.

    When I was in a similar situation I ended up parsing the tree top-down, calling .GetChildren on the top member and then recursively on all descendants. At that point, I could keep track of relationships myself in an explicit manner. More work, I know...

  • JackLacava's avatar
    JackLacava
    Honored Contributor

    I suspect that GetMembersUsingFilter always returns a flat list of members, regardless of the filter expansion you use - hence, without parent IDs set.

    MemberInfo, as a class, can express parent-child relationships and indentation levels, but not all functions that produce MemberInfo objects will actually leverage such power.

    When I was in a similar situation I ended up parsing the tree top-down, calling .GetChildren on the top member and then recursively on all descendants. At that point, I could keep track of relationships myself in an explicit manner. More work, I know...

    • MarkBird's avatar
      MarkBird
      Contributor III

      Thanks Jack, thought that might be your answer!