Referring to one of my earlier blogs about Filter by Attributes, I have got same query from multiple people on how to utilize UDAs in groovy. Suppose you have a Resource dimension in your EPBCS application, in this dimension you have a list of employees and UDAs are tagged for to be hired employees with TBH as follows.

Suppose you want to capture all the employees tagged with TBH

Cube cube = operation.application.getCube("OEP_QTP")
Dimension dim = cube.getApplication().getDimension('Resource');
String memberfunction = 'ILvl0Descendants("Resource")'
def allreps = dim.getEvaluatedMembers(memberfunction,cube)
List<Member> arrMemberswithTBHUDA = []
allreps.findAll{it.toMap().UDA=="TBH"}.each{
     arrMemberswithTBHUDA.add(it)
}

Member List arrMemberswithTBHUDA is populated with employees with UDA set to TBH. As you would notice those lines above have an underlying assumption that each member has only one UDA assigned which may not be the case in most of the applications. To remediate this situation, instead of using equation (==), you can use .contains as follows.

Cube cube = operation.application.getCube("OEP_QTP")
Dimension dim = cube.getApplication().getDimension('Resource');
String memberfunction = 'ILvl0Descendants("Resource")'
def allreps = dim.getEvaluatedMembers(memberfunction,cube)
List<Member> arrMemberswithTBHUDA = []
allreps.findAll{it.toMap().UDA.toString().contains("TBH")}.each{
     arrMemberswithTBHUDA.add(it)
}

You can use arrMemberswithTBHUDA in any way you need depending on what you have been trying to do. One of the most common scenarios is to collect member names and use in a fix statement with join method. you can simply utilize it as follows.

println('''FIX("'''+arrMemberswithTBHUDA.collect{it.toMap().Member}.join('","')+'''")''')

FIX statement is going to be ready for the execution