- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 11:39 AM
Hello,
I am looking for a way to pull the watch list from a new RITM into the SCTask record. I have set up a business rule to run after the Watch List changes, but am having issues getting my code to work. I would appreciate any help on getting this to work from you smart people. Thank you!
(function() {
//get the gliderecord for the parent request
var task = new GlideRecord('sc_task');
if (task.get(current.catalog_task)) {
task.watch_list = current.watch_list;
task.update();
}
})();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 11:54 AM
Hi Josh,
Since this BR is running on the sc_req_item table, 'current' refers to the RITM record that is being changed. There is not a field on the sc_req_item table named catalog_task, so that's where your script is failing. Something like this should work, copying the watch_list to ALL Catalog tasks that exist at the time of the update:
var task = new GlideRecord('sc_task');
task.addQuery('parent', current.sys_id);
task.query();
while (task.next()) {
task.watch_list = current.watch_list;
task.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 11:51 AM
Hello,
Now depending on your requirement, if you want to copy the watchlist values when a sc_task gets created then write a before insert business rule on sc_task table with the below code:-
(function executeRule(current, previous /*null when async*/) {
current.watch_list=request_item.watch_list;
})(current, previous);
Now if you want to update the watchlist on sc_task on change of watchlist value the create a after update business rule on sc_req_item table and use the below code:-
(function executeRule(current, previous /*null when async*/) {
var cat_task = new GlideRecord('sc_task');
if (cat_task.get(current.sys_id)) {
cat_task.watch_list = current.watch_list;
cat_task.update();
}
})(current, previous);
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 12:04 PM
Hello @Josh Hines
If the requirement is to update it always on change of watchlist then what @Brad Bowman has explained is correct I missed the current part while typing the script.
Please follow @Brad Bowman answer.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 11:54 AM
Hi Josh,
Since this BR is running on the sc_req_item table, 'current' refers to the RITM record that is being changed. There is not a field on the sc_req_item table named catalog_task, so that's where your script is failing. Something like this should work, copying the watch_list to ALL Catalog tasks that exist at the time of the update:
var task = new GlideRecord('sc_task');
task.addQuery('parent', current.sys_id);
task.query();
while (task.next()) {
task.watch_list = current.watch_list;
task.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 12:24 PM
Thank you! That worked.