Groovy 32 – Fetch the Dimension Members for the Customer Auxiliary 1 Dimension, for the territories the Account Record Owner is in

The flowing script will return all the members of Auxiliary 1 Dimension, for those territories in which a user is in.

The resource could be Owner or member of the  sales team or simply the login user.

This is the script:

def OwnerID =  <RESOURCE OR USER PARTY ID>       
def colect = []        
def dimMember = []        
def x        
def view_TerrRes = newView(‘TerritoryResourceVO’)        
def CriteriaTerRes = newViewCriteria(view_TerrRes)        
def criteriaRow = CriteriaTerRes.createRow()        
def cr =  criteriaRow.ensureCriteriaItem(‘ResourceId’)        
cr.setOperator(‘=’)        
cr.setValue(OwnerID)        
CriteriaTerRes.insertRow(criteriaRow)        
view_TerrRes.appendViewCriteria(CriteriaTerRes)        
view_TerrRes.executeQuery()        
        
        
while(view_TerrRes.hasNext())        
{        
def terResRow = view_TerrRes.next()        
  colect.add(terResRow.TerritoryVersionId)        
}        
def uniqueTerr = colect.unique()        
def terrNumber =  uniqueTerr.size()        
def col      
for(int i = 0;i<uniqueTerr.size();i++)        
{        
def view_Terr = newView(‘TerritoryDimensionalityPVO’)      
def CriteriaTer = newViewCriteria(view_Terr)        
def criteriaRow1 = CriteriaTer.createRow()        
def cr1 =  criteriaRow1.ensureCriteriaItem(‘TerritoryVersionId’)        
cr1.setOperator(‘=’)        
cr1.setValue(uniqueTerr[i])        
CriteriaTer.insertRow(criteriaRow1)        
view_Terr.appendViewCriteria(CriteriaTer)        
view_Terr.executeQuery()        
if(view_Terr.first()?.DimensionName==“Customer Auxiliary 1”){      
dimMember.add(view_Terr.first()?.DimensionMemberName)      
  }      
      
}        
return dimMember  

dimMember – should be the array holding all Dimension Members for Customer Auxiliary 1

Script can work in a formula field or as a function or in a trigger(have to replace return statement at the end with a setAttribute())

Leave a Reply

Your email address will not be published. Required fields are marked *