how to close Ritm when all SCTask close And get error message user to try close Ritm when any one Sctask is in open state.?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 01:34 AM
Hi All,
I have written business rule on ritm and sc task table
1) if user try to close ritm , it shouldn't close and get error message and revert back to pervious state. Its working fine
Businees rule:
Table Sc_req_item
Before Update BR condition is this
State [IS ONE OF] [Closed Complete, Closed Incomplete, Closed Skipped]
order 1000
var gr = new GlideRecord("sc_task");
gr.addQuery("request_item", current.sys_id);
gr.query();
while (gr.next()) {
if (gr.active == true) {
gs.addErrorMessage("Please close all Sc Tasks and then close RITM");
current.setAbortAction(true);
}
}
2) When all sc task close ritm has to close automatically its also working fine .
Business Rule :
Table sc_task
After Update BR condition is Active changes to false
Order 1000
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.addQuery('active', true);
gr.query();
if (!gr.next()) {
var ritm = current.request_item.getRefRecord();
ritm.state = 3;
ritm.update();
}
Now my issue is user raising the ticket ,for one RITM multiple sctask is there , If user try close the sctask its redirecting to ritm and its showing Error message . My requirement is user try close the SCTASK ticket don't show error message . if user try close Ritm, if any one sc task is open state then error message has to visible . Please help me on this.
Thanks,
Suresh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 02:52 AM
Hii @suresh,
Please change your second BR and just copy and paste the code in BR I have tested this code will resolve your issue for sure, attaching screen shot below:-
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("sc_task");
gr.addQuery("request_item",current.request_item);
//gr.addQuery("state","!=","3,4,7");
gr.addQuery("active",true);
gr.query();
if(!gr.next()){
var ritm = new GlideRecord("sc_req_item");
ritm.addQuery("sys_id",current.request_item);
ritm.query();
if(ritm.next()){
ritm.state = '7';// check state choice
ritm.update();
}
}
})(current, previous);
Regards,
Imran Ahmad
Please Mark Correct Answer:-
Please Mark Helpful:-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 03:34 AM
Hi Ahmed ,
Still its not working same issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 04:10 AM
What issue you are facing now same issue or any thing change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 04:17 AM
Same issue , While closing the sctask and another sctask is creating and redirecting to Ritm, error message also populating .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 04:49 AM
Do Inactive 1st Business rule where you restrict user not to close RITM if related catalog task are not closed and test the second requirement again.
Use my code and try, if still issue occur share the screen shot of scripting.
Regards,
Imran Ahmad.
If resolved Please Mark Correct Answer
Please Mark Helpful:-