Mapping watchlist from RITM to parent REQ record

jaredscharf
Tera Contributor

We have a requirement to map the watchlist from a RITM record to its parent REQ record. What is the best way to do this?

3 REPLIES 3

Diogo Ramos
Giga Sage

You could use either a business rule or a flow to handle the copy of the field to the request, you just have to make sure if there are multiple RITMs under a REQ, that you join the new watchlist members instead of replacing. Also consider doing some cleansing on duplicated users. 


vak
Tera Contributor

Hi @jaredscharf ,

 

You can use the Business rule script to copy the watchlist from an RITM record to the corresponding REQ record:

 

1) Create a Business Rule on the sc_req_item table (RITM table).


2) Set it to run "After Insert" or "After Update" depending on when you want the watchlist to be copied.


3) Use the following script in the Script section:

 

if (current.watch_list) {
// Retrieve the parent request (REQ) record
var req = new GlideRecord('sc_request');
if (req.get(current.request)) {
// Copy the Watchlist from RITM to REQ
req.watch_list = current.watch_list;
req.update(); // Save changes to the REQ record
}
}

 

Thanks

Vivek

 

PrashantLearnIT
Giga Sage

Hi @jaredscharf 

 

 

  • Create a Business Rule on the sc_req_item table.
  • Set the Trigger:
    • When: Before or After Insert/Update
    • Condition: Check if the watch_list field is updated.
  • Script:

// Business Rule on 'sc_req_item' table
(function executeRule(current, previous /*null when async*/) {
if (current.watch_list != previous.watch_list) {
var req = new GlideRecord('sc_request');
if (req.get(current.request)) {
req.watch_list = current.watch_list; // Update watchlist on the parent request
req.update();
}
}
})(current, previous);

 

 

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************