Forum Discussion

WernerN's avatar
WernerN
Contributor
2 months ago

Create Scenario Member from Rule

Dear Community Members,
Found several great posts about creating account members from a rule.  I am trying to clone a scenario member (Forecast with Range defined). 
I have to admit that i am running into a knowledge gap when it comes to how to create some of the properties.

I am reading the properties of my source scenario and naively thought i can just use SetStoredValue with the property of the source scenario.  Got stuck at InputFrequency.

Any pointers to documentation, Golfstream, Community posts, or samples would be greatly appreciated.

  • victortei's avatar
    victortei
    New Contributor III

    WernerN,

    Does your code already create the member and the only issue is with the properties? If the issue is with properties, then which property?

    Keep in mind that creating a member requires two main steps:

    1. Create the member
    2. Add Relationship

    For the first step, if you don't have the code, here's something you can try. Of course, you'll need to create the variables I'm using in this code, but you get the idea of how to do so:

    'Update Dim Name accordingly
    Dim objDim As OneStream.Shared.Wcf.Dim = BRApi.Finance.Dim.GetDim(si, DimensionName)
    						
    'Create New Member
    Dim objMember As New Member(objMemberPk, ChildName, ChildDesc, objDim.DimPk.DimId)
    						
    'Create VaryingMemberProperties object
    Dim objProperties As New VaryingMemberProperties(objMemberPk.DimTypeId, objMemberPk.MemberId, DimConstants.Unknown)
    						
    'Create new member info object for new member
    Dim objMemberInfo As New MemberInfo(objMember, objProperties, Nothing, objDim, DimConstants.Unknown)
    						
    'Modify some member properties.
    Dim newmemberProperties As ScenarioVMProperties = objMemberInfo.GetScenarioProperties()
    										
    'Save the member and its properties.
    Dim isNew As TriStateBool = TriStateBool.TrueValue
    BRApi.Finance.MemberAdmin.SaveMemberInfo(si, objMemberInfo, True, True, False, isNew)

    Please, note that one thing that will vary depending on the dimension you're creating the member is this line mainly:

    Dim newmemberProperties As ScenarioVMProperties = objMemberInfo.GetScenarioProperties()

    Then, to accomplish Step 2, as I mentioned above, here's another sample code to create the relationship:

    Dim NewMemberInfo As MemberInfo  = BRApi.Finance.Metadata.GetMember(si, DimTypeIdName, ChildName)
    Dim NewMemberId As Integer = NewMemberInfo.Member.MemberId
    
    Dim relPk As New RelationshipPk(DimTypeIdName, ParentMemberId, NewMemberId)
    
    Dim rel As New Relationship(relPk, DimID, RelationshipMovementType.InsertAsLastSibling, 1)
    
    Dim relInfo As New RelationshipInfo(rel, Nothing)
    Dim relPostionOpt As New RelationshipPositionOptions()                                         
    
    ' Move the member to the parent
    BRApi.Finance.MemberAdmin.SaveRelationshipInfo(si, relInfo, relPostionOpt)

    Hope this helps!