Mark field true if List type field Contact is added

MStritt
Tera Guru

I have a List Type field on the Account table called Incident Contact (u_incident_contact). It's configured for the Reference table to be the Contact table (customer_contact). So, multiple Contacts can be added to this field. What I want to do, is create a true/false checkbox field on the Contact table, and have it checked/true whenever a Contact is added to this field. So, if I add John Doe to this field, the checkbox will be checked automatically when I view John Doe's contact information/profile. In addition, it would get changed to false, if I remove him from the Incident Contact field on the Account. Keep in mind, there can be multiple Incident Contacts added to this field at one time or at different times. What's the best way to configure that? 

6 REPLIES 6

Ruhee Gupta
Tera Contributor

Hello,

 

Could you try to create an business rule on account table on update. Please check below code -

 

// Business Rule Script
(function executeRule(current, previous /* previous is not used in this example */) {
var accountID = current.sys_id; // Assuming Account table's sys_id field
var incidentContacts = current.u_incident_contact.getRefRecord(); // Get the list of incident contacts

// Loop through each incident contact
for (var i = 0; i < incidentContacts.length; i++) {
var contact = incidentContacts[i];
var contactID = contact.sys_id; // Assuming Contact table's sys_id field
var linked = current.u_incident_contact_linked; // Checkbox field on the Contact table

// Update the checkbox field on the Contact record
var contactUpdate = new GlideRecord('customer_contact');
if (contactUpdate.get(contactID)) {
contactUpdate.u_incident_contact_linked = linked;
contactUpdate.update();
}
}
})(current, previous);

 

Please mark my answer helpful it worked for you.

 

Thanks

Thanks Ruhee.

 

I'll give that a try.

 

Mike

Hi Ruhee,

 

After first configuration, it's not working. But I'm sure I don't have something configured correctly. Here's what I have.

 

New true/false field on the Contact table is u_incident_contact:

Contact_Incident Contact.png

Incident Contact List field (u_incident_contact) on the Account table:

Account_Incident Contact.png

BR on the Account table:

Account_BR_when to run.png

Account_BR_Advanced.png

// Business Rule Script
(function executeRule(current, previous /* previous is not used in this example */) {
var accountID = current.sys_id; // Assuming Account table's sys_id field
var incidentContacts = current.u_incident_contact.getRefRecord(); // Get the list of incident contacts

// Loop through each incident contact
for (var i = 0; i < incidentContacts.length; i++) {
var contact = incidentContacts[i];
var contactID = contact.sys_id; // Assuming Contact table's sys_id field
var linked = current.u_incident_contact; // Checkbox field on the Contact table

// Update the checkbox field on the Contact record
var contactUpdate = new GlideRecord('customer_contact');
if (contactUpdate.get(contactID)) {
contactUpdate.u_incident_contact = linked;
contactUpdate.update();
}
}
})(current, previous);

 

 

 

 

Hi Ruhee,

 

Can you take a look at my most recent reply? See what needs to be changed/updated in the BR/script?

 

Mike