11-14-2022 11:34 PM - last edited on 05-02-2023 10:40 AM by JackLacava
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.
Solved! Go to Solution.
11-17-2022 07:52 AM
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)
11-17-2022 11:00 AM - last edited on 11-18-2022 04:13 AM by JackLacava
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)
11-17-2022 07:52 AM
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)
11-17-2022 11:00 AM - last edited on 11-18-2022 04:13 AM by JackLacava
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)