- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2024 09:44 AM
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. I've created an incident contact (u_incident_contact) true/false field on the Contact table (customer_contact). What I want to do, is have the true/false field set to true, whenever a Contact is added to the u_incident_contact list field on the Account. So, if I add John Doe to this field on the Account, the checkbox will be set to true automatically when I view John Doe's contact record. 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/removed to this field at any time or at different times. I've created a BR on the the Account table with the help of a previous community member. It's not working, and the community member is no longer responding. So, I wanted to post again with the information I have so far, to see why the BR isn't working. Below are screenshots of the 2 fields (Contact/Account), along with screenshots of the BR/script created.
// 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);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2024 08:25 AM
@MStritt Here is the final version.
(function executeRule(current, previous /* previous is not used in this example */ ) {
if (current.u_incident_contact != previous.u_incident_contact) {
var accountID = current.sys_id; // Assuming Account table's sys_id field
var incidentContacts = current.u_incident_contact.split(','); // Get the list of incident contacts
var previousincidentContacts = previous.u_incident_contact.split(','); // Get the list of previous incident contacts
// Loop through each incident contact
for (var y = 0; y < previousincidentContacts.length; y++) {
var prevContact = previousincidentContacts[y];
// Update the checkbox field on the Contact record
var prevContactUpdate = new GlideRecord('customer_contact');
if (prevContactUpdate.get(prevContact)) {
prevContactUpdate.u_incident_contact = false; //set false for previous contacts
prevContactUpdate.update();
}
}
// Loop through each incident contact
for (var i = 0; i < incidentContacts.length; i++) {
var contact = incidentContacts[i];
// Update the checkbox field on the Contact record
var contactUpdate = new GlideRecord('customer_contact');
if (contactUpdate.get(contact)) {
contactUpdate.u_incident_contact = true; //set true for new contacts
contactUpdate.update();
}
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2024 10:24 AM
@MStritt Could you please update the script as follows and check if it works.
(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.split(','); // Get the list of incident contacts
// Loop through each incident contact
for (var i = 0; i < incidentContacts.length; i++) {
var contact = incidentContacts[i];
// Update the checkbox field on the Contact record
var contactUpdate = new GlideRecord('customer_contact');
if (contactUpdate.get(contact)) {
contactUpdate.u_incident_contact =true;
contactUpdate.update();
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2024 11:31 AM
Hi Sandeep!
Thanks for the response. I updated the script, and it does mark the incident contact box on the contact record as true (even when adding multiple contacts to the incident contact list field on the Account). So, works! However, if I then remove that contact from the incident contact list field, the checkbox is still true on the Contact record. I need to have that box changed to false, if they are removed from the incident contact field on the Account.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2024 11:42 AM
@MStritt Here is the script covering both the scenarios.
(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.split(','); // Get the list of incident contacts
if (incidentContacts.length == 0) {
contactUpdate.u_incident_contact = false;
contactUpdate.update();
} else {
// Loop through each incident contact
for (var i = 0; i < incidentContacts.length; i++) {
var contact = incidentContacts[i];
// Update the checkbox field on the Contact record
var contactUpdate = new GlideRecord('customer_contact');
if (contactUpdate.get(contact)) {
contactUpdate.u_incident_contact = true;
contactUpdate.update();
break; //break if the contact is set
}
}
}
})(current, previous);
Please mark the response helpful and correct if it manages to address your requriement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2024 11:53 AM
Sandeep,
This didn't work. Also, now when I add multiple (2 contacts) to the incident contact list field on the Account, only the first contact I entered had the incident contact field change to true. This worked prior to this recent script change.