Oracle EPM: Rename Bulk members using Groovy

 Today while creating application process, one of my team member uploaded metadata for Line of Business with members as "000LOB" in place of agreed "000LB" members. Now there is multiple way to do this: -

1. Delete Old Members and reload all members with correct suffix. This can create an issue if you referred members in data forms or data maps as you have to delete/remove it from there first then only you can delete.

2. Manually rename each member in the application from front end. This can be a time consuming process.

3. Use Excel and Groovy combination and rename members in bulk.

So in today's blog we will talk about the 3rd step. So the first step is to prepare a csv file with below structure: -


Prepare this excel file with all the list of Existing Member in one column followed by New corresponding members in other. Make sure to keep the excel file saved as .csv as i am using the same in my groovy script

Use the below Groovy rule and update it as per your need: -

//define parameters - dimension, file to be processed..
String dimensionName = 'Line of Business'
String renameFileName = 'RC-BulkRename.csv'
Cube[] cubes = operation.application.getCubes()
Dimension dimension = operation.application.getDimension(dimensionName, cubes)

//access meta data file from inbox/outbox directory
csvIterator(renameFileName).withCloseable() { rows ->
//process each row to get old and new member names
rows.eachWithIndex { row, idx ->                  
//ignore the header row and process rest
if(idx > 0) {
List<String> fileRecord = row.collect{it.toString().trim() } as List<String>
if( fileRecord.size() == 2) { 
def (String oldMemberName, String newMemberName) = [ fileRecord[0], fileRecord[1] ]   
print "Renaming $oldMemberName to $newMemberName : "                
//check if the member available in the application
if(dimension.hasMember(oldMemberName,cubes)){
Member oldMember = dimension.getMember(oldMemberName,cubes)
try {
oldMember.rename(newMemberName)
println "Successful"
} catch (Exception e) {           
println "Failed"
throwVetoException("Error Occured while renaming $oldMemberName.  $e.message")                       
}
//throw error if the file not contains proper member name
} else {
println "Failed"
throwVetoException("$oldMemberName is not an existing member")
}                                                                      
}
}
}
}

Once validated, saved and deployed. Execute this and you can see the renamed members in bulk. 
This is a very small blog but hope this will help you all.

!!Happy Reading!!




Comments

Popular posts from this blog

Oracle EPM Planning - Planning, Budgeting, Forecasting, and Long-Range Planning

Oracle EPM Planning Account Dimension: Complete Guide to Member Properties with Examples

Creating your first EPM Application