How do I get the department details from the user profile of the opportunity owner using Groovy?
You can create a Before Update trigger on your Opportunity object to retrieve the department details from the user profile of the opportunity owner using Groovy.
You can use this sample Groovy script to help you get started.
def ownerpartyId = <<Fetch the partyId of the Owner Resource "
def vo = newView('Resource');
def vc = vo.createViewCriteria();
def vcr = vc.createRow();
def vci1 = vcr.ensureCriteriaItem('PartyId');
vci1.setOperator('=');
vci1.setValue(ownerpartyId);
vc.insertRow(vcr);
vo.appendViewCriteria(vc);
vo.executeQuery();
def ownerdept = "";
if (vo.hasNext()) {
def res = vo.next();
ownerdept = res?.DeptMeaning.toString();
}
return ownerdept