Groovy 32 – Fetch the Dimension Members for the Customer Auxiliary 1 Dimension, for the territories the Account Record Owner is in
Groovy Script to Return Auxiliary 1 Dimension Members
This script returns all the members of the Auxiliary 1 Dimension for the territories where a user is involved. The user can be the owner, a member of the sales team, or simply the logged-in user.
Groovy Code
def OwnerID = <RESOURCE OR USER PARTY ID> def collect = [] def dimMember = [] 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() collect.add(terResRow.TerritoryVersionId) } def uniqueTerr = collect.unique() 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
This script can be used in a formula field, as a function, or in a trigger (replace the return
statement with setAttribute()
in a trigger).