- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2018 10:23 AM
Hi,
I have a catalog task associated with the Catalog item. If the catalog task state is set to "Closed Incomplete" or "Closed Skipped", I want to update the same to RITM state as well. I have writtten a business rule to accomplish this. Problem is, when I change the catalog task state to "Closed Incomplete" for the first time, RITM state is changed to "Work in Progress". What am I missing here?
Business Rule condition:
After Update Business rule
Condition: Stage changes to Closed Incomplete or State changes to Closed Skipped
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gq=new GlideRecord('sc_req_item');
gq.addQuery('sys_id',current.request_item);
gs.log("Current request item is "+current.request_item);
gq.query();
if(gq.next()){
gs.log("Inside if");
gs.log("Current state of task is"+current.state);
gq.setValue('state',current.state);
gs.log("Current state of req_item is "+gq.state);
gq.update();
}
})(current, previous);
Thanks.
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2018 10:32 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2018 10:32 AM
try changing your business rule to before instead of after.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2018 10:41 AM
Just throwing this out there, but are the values for those states the same?
As in a '2' for the task, is a 'what' for the item?
It may not be a 1 for 1.
And as the other person mentioned above, should be a before BR (before is best used when setting values).
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2018 10:50 AM
Create a Business Rule for sc_task table with before run , check true for update and set a condition as State changes to Closed InComplete.
Once try the below script. It will help you.
(function executeRule(current, previous /*null when async*/) {
var reqItem= new GlideRecord('sc_req_item');
reqItem.addQuery('sys_id',current.request_item);
reqItem.query();
while(reqItem.next()){
reqItem.setValue('state','4');
reqItem.update();
gs.addInfoMessage(reqItem.number);
}
})(current, previous);
Please Hit ✅Correct(If it is a correct solution) or Hit ✅Helpful(If it is useful).