- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 03:50 PM
I am trying to write a business rule:
- on Update
- table: sc_task
when service catalog task is updated BR runs.
Desired Outcome
When a task is updated by an agent, the business rule gets the value of service catalog variable ("comp_reviewStatus" - 3 options from pulldown) and sets the state on the RITM to either "Work in Progress" or "Awaiting Client.
script is:
(function executeRule(current, previous /*null when async*/) {
var status = current.variables.comp_reviewStatus;
if (status == "under_review") {
current.request_item.state = 2; // Work in Progress
}
else if (status == "awaiting_client") {
current.request_item.state = 5; // Awaiting Client
}
else if (status == "completed") {
current.request_item.state = 2; // Work in Progress
}
})(current, previous);
This is not working and RITM state is not being updated.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 04:11 PM
You should write your code onAfter BR as below.
(function executeRule(current, previous /*null when async*/) {
var status = current.request_item.variables.comp_reviewStatus;
var tr=new GlideRecord('sc_req_item');
tr.addQuery('sys_id',current.request_item);
tr.query();
tr.next();
if (status == "under_review") {
tr.state = 2; // Work in Progress
tr.update();
}
else if (status == "awaiting_client") {
tr.state = 5; // Awaiting Client
tr.update();
}
else if (status == "completed") {
tr.state = 2; // Work in Progress
tr.update();
}
})(current, previous);
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
Regards,
Saurabh
Thanks and Regards,
Saurabh Gupta

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 03:54 PM
Hi kshaw,
Just an input, if you are using flow designer, you can achieve this by leveraging Flow activities. Updating the RITM based on SCTASK state. Did you give it a try?
Thanks,
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 04:11 PM
You should write your code onAfter BR as below.
(function executeRule(current, previous /*null when async*/) {
var status = current.request_item.variables.comp_reviewStatus;
var tr=new GlideRecord('sc_req_item');
tr.addQuery('sys_id',current.request_item);
tr.query();
tr.next();
if (status == "under_review") {
tr.state = 2; // Work in Progress
tr.update();
}
else if (status == "awaiting_client") {
tr.state = 5; // Awaiting Client
tr.update();
}
else if (status == "completed") {
tr.state = 2; // Work in Progress
tr.update();
}
})(current, previous);
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
Regards,
Saurabh
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 04:48 PM
Thank you Saurabh, that worked fine.