EPM GROOVY – A Guide to Member UDA Updates using Business Rules

The Groovy API provides a privileged function to update metadata properties using business rules. Since it’s a privileged function, only administrators are allowed to execute the same. Of late, I have been using the function to rename the members, change the parents, etc. This helps in many ways, as UDAs get a little better since we can filter/choose members based on the UDAs in planning webforms directly. Let’s see how it’s done.

Define the global parameters

We are trying to add a new UDA called ‘Sample UDA’ to the product hierarchy. If the UDA has not been created yet, it will be. We are trying to add a new UDA called “Sample UDA” to the product hierarchy. If the UDA has not yet been created, it will be during the process itself. So it doesn’t need to be explicitly created from the dimension editor before we run this operation.

/* RTPS: */
def cfgCube = "PlanType"
def cfgDimension = "product"
def cfgUda = 'Sample UDA'

Cube cube = operation.application.getCube(cfgCube)
Dimension dimension = operation.application.getDimension(cfgDimension, cube)

Get Existing UDAs attached with the members

It is important to get the previously added UDAs with the members and concatenate them with the new one to be added. Otherwise, already added ones will be dropped from the system. The idea is to update the specified UDA to include descendants of specific parents mentioned below.

//Specify parents
def udaParents = ['Colas']

Iterate thru each parent member, get the IDescendant members, and update the required UDAs.

udaParents.each { parent ->
	def members = dimension.getEvaluatedMembers("""IDescendants("${parent}")""", cube) as List<Member>
	members.each { currMbr ->
		String existingUda = currMbr.toMap().UDA    
		//concat existing uda with the new UDA
		String newUda = existingUda ? "$existingUda,$cfgUda" : cfgUda
		try {        	          
			currMbr.dimension.saveMember(["Member":currMbr.name, "UDA": newUda] as Map<String, Object>)                 	       		
			println "SUCCESS: $currMbr.name : uda $cfgUda has been added"                                   
		} catch (java.lang.Exception e) {
			println "WARNING: $currMbr.name : $e.message"     	
		}               	        
    }     
}

Finally, Execution

There are no UDAs added already to the hierarchies for which I am going to update the UDA.

1st Pass – Execution for “Cola” product
2nd Pass – Execution for “Cola” & “Fruit Soda”

Since the first pass, the UDA for product “Colas” and its descendants has already been updated. The rule might throw an error as we cannot add the same UDA twice. This can be captured in the exception section.

«
»