Forum Discussion

Sweez's avatar
Sweez
Contributor
2 days ago

Help Needed Moving a Scenario Member

I have a need to move a scenario from under a parent to under Root.  Take the example below.  I want to move "Forecast" under Root before "ForecastArchive".  To do that, my plan was to add a relationship for "Forecast" under Root, and then removing the relationship of "Forecast" under "BudgetScenarios".  I am assuming there is not a more direct way to move a member in one step, but would love to be wrong. 

I am having issues with the first step trying to add "Forecast" before "ForecastArchive" under Root.  Below is my code.  Does anyone know what I may be doing wrong?  Bonus points if you also know how to remove the "Forecast" relationship with the parent "BudgetScenarios" to complete the move.  I am sure it's something simple but can't figure it out.  When I run this as an extensibility rule, it completes without error but nothing changes in the sceanrio dimension.  

Dim ForecastArchive_Mem As Member = BRApi.Finance.Members.GetMember(si, DimTypeId.Scenario, "ForecastArchive")
Dim Forecast_Mem As Member = BRApi.Finance.Members.GetMember(si, DimTypeId.Scenario, "Forecast")
Dim scenarioDimPk As DimPk = BRApi.Finance.Dim.GetDimPk(si, "TopScenarioDim")
Dim ForecastArchive_ParMem As Member = BRApi.Finance.Members.GetParents(si, scenarioDimPk, ForecastArchive_Mem.MemberId, True).Item(0)

Dim newRootMemRelPos As New RelationshipPositionOptions
newRootMemRelPos.SiblingId = ForecastArchive_Mem.MemberId
newRootMemRelPos.MovementType = RelationshipMovementType.InsertBeforeSibling

Dim newRootMemRelInfo As New RelationshipInfo
Dim relationship As New Relationship
Dim relationshipPK As New RelationshipPk
relationshipPK.ParentId = ForecastArchive_ParMem.MemberId
relationshipPK.ChildId = Forecast_Mem.MemberId
relationship.RelationshipPk = relationshipPK
newRootMemRelInfo.Relationship = relationship

BRApi.Finance.MemberAdmin.SaveRelationshipInfo(si, newRootMemRelInfo, newRootMemRelPos)

 

3 Replies

  • More testing needed but the below seems to work to add the relationship (i.e. Copy vs Move):

    		Dim ForecastArchive_Mem As Member = BRApi.Finance.Members.GetMember(si, DimTypeId.Scenario, "ForecastArchive")
    		Dim scenarioDimPk As DimPk = BRApi.Finance.Dim.GetDimPk(si, "TopScenarioDim")
    		Dim ForecastArchive_ParMem As Member = BRApi.Finance.Members.GetParents(si, scenarioDimPk, ForecastArchive_Mem.MemberId, True).Item(0)
    
    		Dim Forecast_Mem As Member = BRApi.Finance.Members.GetMember(si, DimTypeId.Scenario, "Forecast")
    
    		Dim relPositionOpt As New RelationshipPositionOptions()
    		relPositionOpt.SiblingId = ForecastArchive_Mem.MemberId
    		relPositionOpt.MovementType = RelationshipMovementType.InsertBeforeSibling
    
    		Dim relPk As RelationshipPk = New RelationshipPk(DimTypeId.Scenario, ForecastArchive_ParMem.MemberId, Forecast_Mem.MemberId)
    		Dim relPkList As New List(Of RelationshipPk)
    		relPkList.Add(relPk)
    
    		Dim rel As New Relationship(relPk, scenarioDimPk.DimId, RelationshipMovementType.InsertBeforeSibling, 1)
    		Dim relInfo As New RelationshipInfo(rel, Nothing)
    		BRApi.Finance.MemberAdmin.SaveRelationshipInfo(si, relInfo, relPositionOpt)
    
    		BRApi.Finance.MemberAdmin.CopyOrMoveRelationships(si, scenarioDimPk, relPkList, ForecastArchive_ParMem.MemberId, False, relPositionOpt)

     

     

  • Henning's avatar
    Henning
    Icon for OneStream Employee rankOneStream Employee

    Hi, why not just do it manually? 

    Right-click on the scenario member and select "Copy Selected Members". Then right-click on Hierarchy (as in Root), and select "Paste Relationship (Move)". That will do what you aim for according to your description. Nice and simple 🙂

    • Sweez's avatar
      Sweez
      Contributor

      Thanks but trying to do this via an extensibility rule which I think is much more difficult.  Any idea how to do it that way?