- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2019 11:00 AM
I have a variable set with a field of "requested_for" on every catalog item. I need that field to be copied to the watch list so that the requested for can receive email notifications.
I've seen some articles on this subject but none really seem to answer the question.
I know that I can do this through a business rule - I need help with what I need to do for a script. Any help is appreciated.
~Rachel
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 05:19 AM
Probably the easiest way would be to create an onBefore Business rule on the Requested Item table that will take the value from the Requested for [requested_for] variable and insert into the Watch list [watch_list] listing. Since the Watch list field is an array of sys_id values, you will need to push the value from your variable (which I am guessing is a reference field) into the Watch list field. Here are the details for the Business Rule:
Name: Set Watch list from Requested for
Table: Requested Item [sc_req_item]
Advanced: true
Description: Copies the Requested for variable into the Watch list field
When: before
Order: 100
Insert: true
Update: false
Delete: false
Query: false
Script:
(function executeRule(current, previous /*null when async*/) {
var reqFor = current.variables.requested_for;
var wlArray = [];
if (reqFor != '') {
wlArray.push(reqFor.toString());
current.watch_list = wlArray.toString();
}
})(current, previous);
Let us know if this works for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 04:09 AM
1. The requested_for variable is a reference type variable
2. It is to be copied to the requested item table - sc_req_item
Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 05:19 AM
Probably the easiest way would be to create an onBefore Business rule on the Requested Item table that will take the value from the Requested for [requested_for] variable and insert into the Watch list [watch_list] listing. Since the Watch list field is an array of sys_id values, you will need to push the value from your variable (which I am guessing is a reference field) into the Watch list field. Here are the details for the Business Rule:
Name: Set Watch list from Requested for
Table: Requested Item [sc_req_item]
Advanced: true
Description: Copies the Requested for variable into the Watch list field
When: before
Order: 100
Insert: true
Update: false
Delete: false
Query: false
Script:
(function executeRule(current, previous /*null when async*/) {
var reqFor = current.variables.requested_for;
var wlArray = [];
if (reqFor != '') {
wlArray.push(reqFor.toString());
current.watch_list = wlArray.toString();
}
})(current, previous);
Let us know if this works for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2020 10:06 AM
I did a variation on this, because I had a list of email addresses in a text field (semi-colon separated) and needed to parse them into the watch_list. It also works great for an email List Collector, so bonus win. Couldn't have done it without your example, so thanks!
(function executeRule(current, previous /*null when async*/) {
var inputStr = current.variables.u_lookup_email.toString();
var outputStr = inputStr.split(';');
var strArr = [];
for (var i = 0; i < outputStr.length; i++) {
strArr.push(outputStr[i]);
current.watch_list = strArr.toString();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2019 09:06 AM
ccajohnson - THANK YOU for the quick response and the solution.
This works like a charm and completely solves the issue at hand.