Mark field true if List type field Contact is added
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 09:29 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. 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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2024 06:23 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2024 03:36 PM
Thanks Ruhee.
I'll give that a try.
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2024 09:58 AM
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:
Incident Contact List field (u_incident_contact) on the Account table:
BR on the Account table:
// 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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2024 07:16 AM
Hi Ruhee,
Can you take a look at my most recent reply? See what needs to be changed/updated in the BR/script?
Mike