Forum Discussion

ccage's avatar
ccage
New Contributor II
3 years ago

Updating Entity Relationship for Percent Ownership

Can any one provide me with a rule snippet for updating Entity Percent Ownership. I have tried a few things using the SaveRelationshipInfo but it is not working.
  • JackLacava's avatar
    3 years ago

    This should work, but please make sure you understand what it does before dropping it into production code. You might want to surround the SaveRelationshipInfo call with a try/catch to be on the safe side. As for anything posted on these forums, we make no guarantees in terms of support, you're on your own.

    ' coordinates
    Dim myScenarioID As Integer = brapi.Finance.Members.GetMemberId(si, DimType.Scenario.Id, "Actual")
    Dim myScenarioType As ScenarioType = BRApi.Finance.Scenario.GetScenarioType(si, myScenarioID)
    Dim myTimeID As Integer = BRApi.Finance.Time.GetIdFromName(si, "2020M3")
    Dim myEntityID As Integer = BRApi.Finance.Members.GetMemberId(si, DimType.Entity.Id, "Frankfurt")
    Dim myParentID As Integer = BRApi.Finance.Members.GetMemberId(si, DimType.Entity.Id, "Europe")
    
    ' fetch relationship. 
    Dim relationship As Relationship = BRApi.Finance.members.ReadRelationshipNoCache(si, _
    		DimType.Entity.Id, myEntityID, myParentID)
    ' create new properties
    ' this should leave other properties alone and just merge with existing values, but check; worst case, repro other props before saving
    Dim newProperties As New VaryingMemberProperties( DimType.Entity.Id, myEntityID, myParentID )
    newProperties.GetEntityRelationshipProperties().PercentOwnership.SetStoredValue( _ 
    		myScenarioType.Id, myTimeID, 40.0)
    ' we only save properties in this case
    brapi.Finance.MemberAdmin.SaveRelationshipInfo(si, _
    	False, relationship, _
    	True, newProperties, _
    	Nothing)

     

  • ccage's avatar
    3 years ago

    Thanks Jack! I want to also thank Nick Kroppe who provided me with the following code as well.

    'retrieve rel info for parent child relationship
    Dim myRelInfo As RelationshipInfo = BRApi.Finance.Members.GetRelationshipInfo(si, _
        dimTypeId.Entity, "Houston Heights", "Houston")
    
    'retrieve entity properties
    Dim entityRelationProps As EntityRelationshipVMProperties = myRelInfo.GetEntityRelationshipProperties()
    
    'set the percent ownership property
    entityRelationProps.PercentOwnership.SetStoredValue( _
        scenarioTypeId.Unknown, SharedConstants.Unknown, 90)
    
    'retain the current relationship hierarchy position
    Dim relationPosOpts As New RelationshipPositionOptions()
    relationPosOpts.SiblingId = SharedConstants.Unknown
    relationPosOpts.MovementType = RelationshipMovementType.RetainCurrentPosition
    
    'save the relationship info and update the ownership property
    BRApi.Finance.MemberAdmin.SaveRelationshipInfo(si, _
        True, myRelInfo.Relationship, _
        True, entityRelationProps.VMProperties, _
        relationPosOpts)