determining parent by hierarchy
tldr: What's a performant, reliable way to determine a member's parent within a given hierarchy?
I have been developing a custom extender rule to automate OneStream metadata updates based on our master metadata source. One of the last remaining tasks to solve is how to correctly execute member moves. As OneStream can have a given member exist multiple times in the same dimension, the only way to execute a move in OneStream is by specifying "move from parent A to parent B." Parent B is quite easy to determine as our metadata source provides this information per-hierarchy and does not allow duplicates but it does not tell us parent A, or even if there was a move at all.
This means I have to validate that the specified member 1) is under the same parent that our metadata source says it should be and 2) isn't anywhere else in the hierarchy.
However, in OneStream, I know of no way to query the parent(s) of a member but only those within a specific hierarchy. I've never needed to do this in a BR before but I have definitely been stung by this limitation while working with QVs in the past. This makes it feel like a common-enough need that there's probably a way to do it that I'm just unaware of. If not, I'll have to code it myself and I could use some insight into a performant and logically-sound way to do it.
So far, the only approach I can imagine is this:
- BR API GetDescendants to pull all members in a hierarchy.
- Verify the child exists in the hierarchy.
- BR API GetParents to pull all parents of the child.
- Iterate through each parent to see which one(s) exists in the hierarchy.
- If there's only one and it differs from the one provided by our metadata source, move it. If there are multiple, oh bother.
However, I foresee a lot of unpleasant little surprises in developing this. I also worry about performance as there's a Cartesian product of the number of descendants times the number of parents. Even if it's speedy, it still seems like a very indirect route to take for what is conceptually simple.
What's the better way to do this?