How to set watchlist user based on account in case table

sriram35
Kilo Guru

Hi Team,

 

I want to set watchlist user on case table, based Account then contact Relationships. In contact Relationships I have 3 contacts I need to all the three in watchlist field once they select that Account.

 

sriram35_0-1740997569470.png

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@sriram35 

so when case is created you can fetch the contact relationships using the account field on Case

what did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

 

(function executeRule(current, previous /*null when async*/) {

    if (!current.account) {
        return;
    }

    var watchlistUsers = [];

    var gr = new GlideRecord('sn_customerservice_contact_relationship'); // Contact Relationships table
     gr.addQuery('company', current.account); 

    while (gr.next()) {
        if (gr.contact) { 
            watchlistUsers.push(gr.contact.toString()); 
        }
    }

    if (watchlistUsers.length > 0) {
        current.watch_list = watchlistUsers.join(','); // Update Watchlist field
    }

})(current, previous);

Hi @sriram35 ,

the query statement is missing in the script 

try this

(function executeRule(current, previous /*null when async*/ ) {

    if (!current.account) {
        return;
    }

    var watchlistUsers = [];

    var gr = new GlideRecord('sn_customerservice_contact_relationship'); // Contact Relationships table
    gr.addQuery('company', current.account);
    gr.query();

    while (gr.next()) {
        if (gr.contact) {
            watchlistUsers.push(gr.getValue('contact'));
        }
    }

    if (watchlistUsers.length > 0) {
        current.watch_list = watchlistUsers.join(','); // Update Watchlist field
    }

})(current, previous);

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

@sriram35 

please add this line and see if it works

    gr.query();
 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader