Forum Discussion

mpavan's avatar
mpavan
New Contributor II
3 months ago

Rename 500+ members in onestream

Hello Experts,  Is there a way to update 500+ member names in OneStream using XML file. Manually changing each member is time consuming there seems to be no functionality available with XML load? T...
  • jwagner's avatar
    3 months ago

    I just had this use case come up recently.  I wrote a business rule that renames members based on a member filter.  I needed this rule to rename a number of members with a suffix/prefix due to extensibility in the account dimension.   See code below.  I have the code set up to be just base members of a top parent member, any member filter will work.  (See line 43 for member Filter)

     

     

     

     

    Imports System
    Imports System.Data
    Imports System.Data.Common
    Imports System.IO
    Imports System.Collections.Generic
    Imports System.Globalization
    Imports System.Linq
    Imports Microsoft.VisualBasic
    Imports System.Windows.Forms
    Imports OneStream.Shared.Common
    Imports OneStream.Shared.Wcf
    Imports OneStream.Shared.Engine
    Imports OneStream.Shared.Database
    Imports OneStream.Stage.Engine
    Imports OneStream.Stage.Database
    Imports OneStream.Finance.Engine
    Imports OneStream.Finance.Database
    
    Namespace OneStream.BusinessRule.Extender.BulkRenameMembers
    	Public Class MainClass
    		Dim m_LogBuilder As StringBuilder = New StringBuilder()
    		Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As Object
    			Try
    		
    							
    				Dim dimName As String = "Dimension Name"
    				Dim topMember As String = "Top Member in Dimension"
                    Dim preSufFlag As String = "Prefix"
                    Dim renameString As String = "PREFIX"
    		
                    Me.RenameBaseMembers(si, dimName, topMember)
    
    
    				Return Nothing
    			Catch ex As Exception
    				Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
    			End Try
    		End Function
    		
    		Public Sub RenameBaseMembers(ByVal si As SessionInfo, dimName As String, topMember As String, preSufFlag As String, renameString As String)
    			Dim dimPk = BRAPI.Finance.Dim.GetDimPk(si, dimName)
                'Modify below as needed for use case.
    			Dim baseMemberLst = BRAPI.Finance.Members.GetMembersUsingFilter(si, dimPk, $"A#[{topMember}].Base.Remove(None)", True)
    			Me.AddToLog(si, "Member Rename Process Triggered" & vbCrLf & $"Dimension Name: {dimName}" & vbCrLf & $"Top Member: {topMember}" & vbCrLf & $"Members to be Modified: {baseMemberLst.Count}")
    
    			For Each mbrInfo As MemberInfo In baseMemberLst.AsEnumerable()
    				Dim oldMbrName = mbrInfo.Member.Name
    				Dim newMbrName As String
    				If preSufFlag.XFContainsIgnoreCase("Prefix") Then 
    					'Prefix all member names
    					newMbrName = renameString & "_" & oldMbrName  
    				Else
    					'Suffix all member names
    					newMbrName = oldMbrName & "_" & renameString
    				End If
    				Try
    					BRAPI.Finance.MemberAdmin.RenameMember(si,dimPk, oldMbrName, newMbrName) ' Comment this out to test...
    					AddToLog(si, $"Member Renamed." & vbCrLf & $"Old Member Name: {oldMbrName}" & vbCrLf & $"New Member Name: {newMbrName}")
    				Catch ex As Exception
    					AddToLog(si, $"Error Renaming Member - {oldMbrName}")
    					BRAPI.ErrorLog.LogMessage(si, m_LogBuilder.ToString())
    					Continue For
    				End Try
    				Next
    			BRAPI.ErrorLog.LogMessage(si, m_LogBuilder.ToString())
    		End Sub
    		
    		#Region "Logging"
    		Public Sub AddToLog(ByVal si As SessionInfo, ByVal message As String)
    			m_LogBuilder.AppendLine(message)
    			m_LogBuilder.AppendLine("---------------------------------------")
    		End Sub
    		#End Region 
    	End Class
    End Namespace

     

     

     

     

  • mpavan's avatar
    mpavan
    3 months ago

    Thank you for the sample script. In our case there was no logic behind it and the changes are random. I had got the following script and it works. (I will be populating the Key Value Pairs in Excel and paste in script)

     
    Dim dimName As String = "Toal_ProductDim"
    Dim dimPk = BRAPI.Finance.Dim.GetDimPk(si, dimName)
        ' Initialize a dictionary to store key-value pairs
        Dim keyValuePairs As New Dictionary(Of String, String)
     
        ' Add key-value pairs
        keyValuePairs.Add("mj1", "TestU1")
        keyValuePairs.Add("mj2", "TestU2")
        keyValuePairs.Add("mj3", "TestU3")
    For Each kvp As KeyValuePair(Of String, String) In keyValuePairs
    BRAPI.Finance.MemberAdmin.RenameMember(si,dimPk, kvp.key, kvp.value)
    BRApi.ErrorLog.LogMessage(si,kvp.Key & kvp.Value)
        Next