Access Contact Object From Accounts Using Groovy Script (Doc ID 2262672.1)

Last updated on MAY 17, 2017

Applies to:

Oracle Fusion Sales Cloud Service - Version 11.1.11.1.0 and later
Information in this document applies to any platform.

Goal

Customer has added 'BLACKLISTED' to the LOV of Account Type.

Now, using Groovy scripting, they want to achieve the following requirement: whenever an Account is flipped to 'BLACKLISTED', then the OoTB API name field DoNotCallFlag of linked contacts to that account should be automatically checked.

How can this be achieved?

They have currently an 'After Insert' trigger on Account object:

println("AccType_Blacklisted is triggered");

def AccType = AccountType_c;

def relIterator = Relationship;
relIterator.reset();
def relRow;
def relObjectId;
def relType;

def alContactPartyId = new ArrayList();
def i = 0;

//add to an array list all the object ids of the relations of type Contact
while(relIterator.hasNext())
{
relRow = relIterator.next();
relObjectId = relRow.ObjectId;
relType = relRow.RelationshipType;
if (relType=='CONTACT')
{
alContactPartyId[i] = relObjectId;
i++;
}
}

def contactObj;
def ContactPartyId;
def voPersonProfile;
def vc;
def vcr;
def vci;
def n=i;
for(i=0;i<n;i++)
//get the information relevant for each of the contacts that were returned in the relations
{
ContactPartyId = alContactPartyId[i];
voPersonProfile = newView('PersonProfile');
vc = newViewCriteria(voPersonProfile);
vcr = vc.createRow();
vci = vcr.ensureCriteriaItem('PartyId');
vci.setOperator('=');
vci.setValue(ContactPartyId);
vc.insertRow(vcr);
voPersonProfile.appendViewCriteria(vc);
voPersonProfile.executeQuery();

//since we are querying for the id only one record will be returned in each query
contactObj = voPersonProfile.next();
//check DoNOtCall, DoNotEmail
if (AccType == 'BLACKLISTED')
{
println("AccType is BLACKLISTED");
contactObj.setAttribute('DoNotCallFlag','Y');
contactObj.setAttribute('DoNotContactFlag','Y');
contactObj.setAttribute('DoNotEmailFlag','Y');
contactObj.setAttribute('DoNotMailFlag','Y');
}
else
{
println("AccType is not BLACKLISTED");
contactObj.setAttribute('DoNotCallFlag','N');
contactObj.setAttribute('DoNotContactFlag','N');
contactObj.setAttribute('DoNotEmailFlag','N');
contactObj.setAttribute('DoNotMailFlag','N');
}
//throw new oracle.jbo.ValidationException('List of contacts first name' + sFirstNamesConcat);
}
 

Solution

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms