- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2020 11:10 AM
We have requirement, when we RITM state changes to Close Complete/Incomplete/skipped the its related service catalog task should also close. For that i wrote the below business rule but is is not working, can someone please assist?
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request_item',current.request_item);
gr.addQuery('active',true);
gr.query();
if(!gr.next()) {
var sc_task = new GlideRecord('sc_task');
sc_task.addQuery('sys_id',current.request_item);
sc_task.query();
if(sc_task.next())
{
//update the fiel of sc_task
sc_task.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2020 04:16 AM
Thanks Alok, Business rule is working but when i tried cancelling the RITM from portal it is not working. As you said may be i should include script in widget itself.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2020 02:16 AM
Hello, Niharika,
I got your point,
So on close of ritm if you want to close the request and related task, please use the below code
To close the RITM.
current.state=3;
//to close the Task
var grtask=new GldieRecord('sc_task');
grtask.addQuery('request_item',current.sys_id);
grtask.query();
while(grtask.next())
{
grtask.state=3;//assumuning 3 as the closed complate state value,please put write value here.
}
//to close the request on click of the close button in ritm
current.request.state='closed_complete';//assumuing closed_complete as state backend value on request table,please update right value
Please Mark it helpful/correct if my answer helps in any way to resolve your query.
Reach out to me if any more help required.
Regards
Yash.K.Agrawal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2020 02:54 AM
I tried the code in business rule and it is not working 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2020 02:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2020 03:17 AM
Hello Niharika,
Please note-
When you close the tasks and set the state of the RITM to closed complete, the request will be automatically closed by the business rule that is available out of the box.
Please use the below one,
if(current.state=7)//assuming 7 us the state value for closed
//to close the Task
var grtask=new GldieRecord('sc_task');
grtask.addQuery('request_item',current.sys_id);
grtask.query();
while(grtask.next())
{
grtask.state=7;//assumuning 3 as the closed state value,please put write value here.
}
Please try the above one by manually close the ritm, and then click on Ui action.
Regards
Yash Agrawal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2020 03:29 AM
Hi Niharika,
First thing I would like to say that the best approach would be achieving the same with the script in the cancel button itself.
However, since you are approaching with the Business rule I would like to say it should be an After update business rule you should uncheck the insert checkbox because which creating RITM it will not be in cancel state.
Now coming to the scripting part.
You should configure like below:
Condition: Replace with the correct value of cancel of RITM state
current.state.changesTo(4);
Script: Don't forget to add active query otherwise it will update the state of other tasks also which are completed.
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('sc_task');
gr.addActiveQuery();
gr.addQuery('request_item', current.getUniqueValue());
gr.query();
while (gr.next()) {
gr.setValue('state', 4); //replace 4 with the correct value of state which you want to update
gr.update();
}
})(current, previous);
Kindly mark my answer as Correct and helpful based on the Impact.
Regards,
Alok