- 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 04:37 AM
Try this
add the condition assigned_to changes
var user = current.assigned_to;
var req = current.request_item;
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id',req);
gr.query();
if(gr.next()){
gr.watch_list = gr.watch_list + user;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 04:51 AM
Hi Suvro,
It's not working still. BR is after update/insert. Is it ok?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 04:37 AM
Hello,
Define a BR on catalog task table...
condition
current.assigned_to.changes() && current.assigned_to != ''
script
var ritm = current.request_item.getRefRecord();
var wlArr = ritm.watch_list.toString().split(',');
wlArr.push(current.assigned_to.toString());
ritm.watch_list = wlArr.join();
ritm.update();
getRefRecord() should work
GlideRecord is not required please try this solution.
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 04:56 AM
Hi Rasheed,
Your solution is working for me but when assigned to is getting changed then it is adding new record in watchlist and not deleting the previous one. Do you know how it can be fixed?