How to add Variable set users in Notification.

sattar3
Tera Contributor

Hello All,

 

We got a requirement from customer like when RITM gets updated or any comments added in the RITM then an email notification will be send to User/Group Watchlist members.

 

For that I created a Variable Set, in that i have created 2 variables with list collector type.

1. User Watchlist-reference to user table.

2.Group Watchlist-reference to group table.

 

I have created a new Notification to sc_req_item table but i'm unable to select Variable set or variables inside variable set so that those members can get emails.

 

Please help me how we can achieve this and what are steps needs to be followed.

Can we achieve this by email script?

 

@Ankur Bawiskar @Community Alums 

 

Thanks,

Abdul

1 ACCEPTED SOLUTION

@sattar3 

why would the variable change later on? Ideally they should not once RITM is submitted.

It's not recommended.

you can use workflow run script to set the fields using the variables

Simply use this logic

1) when RITM is created populate the fields on RITM with the variable values -> workflow run script

current.setValue('watch_list', current.variables.users_watchlist.toString());

current.setValue('group_list', current.variables.group_watchlist.toString());

2) then have Insert, Update Notification and set the recipient as those 2 fields

AnkurBawiskar_2-1709900683715.png

 

3) condition is Comments changes

AnkurBawiskar_1-1709900631265.png

 

 

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

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@sattar3 

you can use this logic

1) use after insert BR on RITM or use workflow run script

2) get the users from both the variables and use gs.eventQueue() based approach to send the email

3) create event, email on RITM table

I hope you are aware how to create event, link it with email and use eventQueue()

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

Thanks @Ankur Bawiskar . It works when RITM is created and then we update the ritm. 

I think we need to update the BR script, i think some logic is missing.

 

I created a Before Insert/Update BR on RITM table, please check and correct the script if i did anything wrong.

 

BR script:

(function executeRule(current, previous /*null when async*/) {
    // Check if the variables have been modified
    if (current.variables.users_watchlist.changes() || current.variables.group_watchlist.changes()) {
       
        // Get the selected users and groups from the variables
        var usersWatchlist = current.variables.users_watchlist.toString();
        gs.info('Users in Variable '+usersWatchlist);
        var groupsWatchlist = current.variables.group_watchlist.toString();
        gs.info('Groups in Variable '+groupsWatchlist);

        // Update the sc_req_item fields
        current.setValue('watch_list', usersWatchlist);
        current.setValue('group_list', groupsWatchlist);

        gs.info("Watchlist and GroupList fields updated for sc_req_item " + current.number);
    }
})(current, previous);
 
When a RITM is created from Portal or from the backend the Watch List and Group List is not populating.
When i tried to update the users and groups after Creation of RITM, then it populates both watchlist and group list.  
 
 
Thanks,
Abdul

@sattar3 

why would the variable change later on? Ideally they should not once RITM is submitted.

It's not recommended.

you can use workflow run script to set the fields using the variables

Simply use this logic

1) when RITM is created populate the fields on RITM with the variable values -> workflow run script

current.setValue('watch_list', current.variables.users_watchlist.toString());

current.setValue('group_list', current.variables.group_watchlist.toString());

2) then have Insert, Update Notification and set the recipient as those 2 fields

AnkurBawiskar_2-1709900683715.png

 

3) condition is Comments changes

AnkurBawiskar_1-1709900631265.png

 

 

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 Thanks Ankur.

 

It works, I used Workflow instead BR.

sattar3_0-1709901596930.png

 

 

Thanks,

Abdul

@sattar3 

Glad to know.

Please mark my response as correct and close the thread

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