- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 04:29 AM
Hi, I am trying to add the user from sc_task field 'assigned to' to the RITM form field 'watchlist'.
Watchlist is a glide list type field.
When the assigned to is filled on sc_task form then the user should get filled on watchlist on ritm.
Kindly help in achieving this.
I have made a after insert/update BR on sc_task.
Condition is when Assigned to is not empty.
Script
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var user = current.assigned_to;
var req = current.request_item;
var gr = new GlideRecord(sc_req_item);
gr.addQuery('number',req);
gr.query();
if(gr.next()){
gr.watch_list = user;
gr.insert();
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 05:27 AM
Hello,
Try below. Don't forgot to mark my answer as correct if that helps
var ritm = current.request_item.getRefRecord();
var wlArr = ritm.watch_list.toString().split(',');
var idx = wlArr.indexOf(previous.assigned_to.toString()); //get the index of sys_id of user you want to remove from watch list.
wlArr.splice(idx,1); // Remove the specific user from array. idx is the index from which you want to remove and '1' is the number of elements you want to remove.
wlArr.push(current.assigned_to.toString());
ritm.watch_list = wlArr.join();
ritm.update();
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 05:27 AM
Hello,
Try below. Don't forgot to mark my answer as correct if that helps
var ritm = current.request_item.getRefRecord();
var wlArr = ritm.watch_list.toString().split(',');
var idx = wlArr.indexOf(previous.assigned_to.toString()); //get the index of sys_id of user you want to remove from watch list.
wlArr.splice(idx,1); // Remove the specific user from array. idx is the index from which you want to remove and '1' is the number of elements you want to remove.
wlArr.push(current.assigned_to.toString());
ritm.watch_list = wlArr.join();
ritm.update();
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 05:49 AM
Hi Rasheed,
It is working for me now. Thank you for your support and help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 04:39 AM
Hey,
I can see a few issues with your script, please follow below script:
var user = current.getValue("assigned_to");
var reqItem = current.getValue("request_item");
var grItem = new GlideRecord("sc_req_item");
if(grItem .get(reqItem)){
var getExisitngList = grItem.getValue("watch_list").split(',');
getExisitngList.push(user);
grItem.setValue("watch_list", getExisitngList.join(','));
grItem.update();
}
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 06:15 AM
Hi
For your requirement, you can follow the below-provided approach:
- Requested Item backend name on sc_task: request_item
- Business Rule on sc_task:
- When: Before
- Insert: True
- Update: True
- Condition: Assigned To â–º Changes
- Script:
(function executeRule(current, previous /*null when async*/) { var reqWatchList = [], arrayUtil = new ArrayUtil(), oldAgent = JSUtil.notNil(previous.assigned_to + '') ? previous.assigned_to + '' : '', newAgent = JSUtil.notNil(current.assigned_to + '') ? current.assigned_to + '' : '', reqItem = current.request_item.getRefRecord(); //Get the GlideRecord object of the RITM //-----Logic to add Assigned to in RITM----- reqWatchList = reqItem.watch_list.split(','); reqWatchList.push(newAgent); //-----Logic to remove previous Assigned to in RITM----- if(oldAgent) { reqWatchList.splice(reqWatchList.indexOf(oldAgent),1); } //Remove duplicate entries if any reqWatchList = arrayUtil.unique(reqWatchList); reqItem.watch_list = reqWatchList.join(','); reqItem.update(); })(current, previous);
Please try and let me know if this works for you or not.
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik