How do I save a Member to the root of a dimension

Valued Contributor
Originally posted by Steve Davis

How do I save a Member to the root of a dimension (as a child of Hierarchy)?

I have tried the SaveMemberAndRelationshipInfo method, but this gives me the error:  Error creating parent-child relationship.  Invalid Parameter. child, [CHILDNAME].



New Contributor

The workaround I've found was to find all the parents of a sibling member that rolls up to the root, and then just picking the first one:

BRApi.Finance.Members.GetParents(si, dimPk, sibling, includeRootMemberInResult, dimDisplayOptions).Item(0)

Valued Contributor
				Dim newMember As MemberInfo = Nothing
				'Get the dimension parent member which will give us the dimension / relationship info need to create the member
				Dim parentMem As MemberInfo = BRApi.Finance.Metadata.GetMember(si, dimTypeId, parentName)
			    If Not parentMem Is Nothing Then                                                                                                                                            
					'Control Switches
					Dim saveMember 			As Boolean = True 
					Dim saveProps 			As Boolean = True
					Dim saveDescs 			As Boolean = False
					Dim saveRelationship 	As Boolean = True
					Dim isNewMember 		As Boolean = True

					'Other parameters that we are not using but must be supplied
					Dim varProps 			As VaryingMemberProperties 		= Nothing
					Dim altDescList 		As List(Of MemberDescription) 	= Nothing
					'Dim dimensionId As Integer
					Dim dimensionPk 		As New DimPk(BRApi.Finance.Dim.GetDim(si,dimensionName).DimPk)'(dimTypeId, parentMem.Member.DimId)
					Dim newMemPk 			As New MemberPk(dimTypeId, DimConstants.Unknown)
					Dim newMem 				As New Member(newMemPk, memberName, memberDesc, dimensionPk.DimId)

					Dim relPk 				As New RelationshipPk(dimTypeId, parentMem.Member.MemberId, DimConstants.Unknown)
					Dim rel 				As New Relationship(relPk, newMem.DimId, RelationshipMovementType.InsertAsLastSibling, 1)
					Dim relInfo 			As New RelationshipInfo(rel, Nothing)
					Dim relPostionOpt 		As New RelationshipPositionOptions()                                                                                                                                      

					'Create the member and relationship
					Dim metaAdmin 			As New MetadataAdmin
					Dim newRelPK 			As RelationshipPk 
					newRelPK = metaAdmin.SaveMemberAndRelationshipInfo(si, dimensionPk, saveMember, newMem, saveProps, varProps, saveDescs, _
																		altDescList, saveRelationship, relInfo, relPostionOpt, isNewMember)
					'Get the newly added member and return it
					If Not newRelPK Is Nothing Then
						newMember = BRApi.Finance.Metadata.GetMember(si, dimTypeId, newRelPK.ChildId)
					End If    
				End If

				Return newMember