Metadata and Groovy - Bulk Update Members through Groovy
Shehzad Kazmi
Digital Transformation Specialist | EPM Solutions Advisor | Budgeting & Planning | Profitability and Costing | Helping businesses to realize value from their EPM investments
Use a simple CSV and groovy to bulk update member properties
In this part of the Metadata and Groovy series, I will explore how you can harness the capabilities of Groovy to bulk update dimension members using a CSV file.
The CSV Format
We plan to update the members so first we must identify the member. Instead of just having one column for member name (and having to search every dimension to locate the member), I wanted to identify each unique member using two columns
All other columns of the CSV must have the same name as the property we need to update. It could be one property or three or twenty.
Not every property must have a value when updating members in bulk. We will ignore cells that are blank so that we only update the member property if there is a cell value.
领英推荐
The Code
/*RTPS:*/
Application app = operation.application
Cube[] cube = app.getCubes()
Map columnMap = [:]
csvIterator('Metadata Update.csv').withCloseable() { reader ->
String[] headers = reader.next()
headers[2..-1].eachWithIndex { header, index -> columnMap[index] = header }
reader.each { String[] values ->
Dimension dim = app.getDimension(values[0], cube)
Member mbr = dim.getMember(values[1], cube)
if (mbr) {
def mbrProperties = mbr.toMap()
values[2..-1].eachWithIndex { value, index ->
if (value != "") { mbrProperties << ([(columnMap[index]):value] as Map) }
}
mbr = dim.saveMember(mbrProperties, DynamicChildStrategy.NEVER_DYNAMIC)
}
}
}
I had some thoughts on other features that can be added on to make this more robust:
Summary
In this first article in the _Groovy and Metadata_ series, I have covered how you can bulk update metadata of a dimension Member building on what we've learned in the previous articles in this series.