- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2017 07:28 AM
Hi,
I want to Prevent users from closing RITM if any of its TASK is still open.
Any help is highly appreciated.
Thanks,
Aamir
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2017 08:51 AM
Hi Aamir,
you are right, I missed it, you have to set the state to the previous value as well:
var task = new GlideRecord('sc_task');
task.addQuery('request_item', current.sys_id);
task.addActiveQuery();
task.query();
if(task.hasNext()){
gs.addErrorMessage('Please, close all Tasks before to close the Request Item');
current.state = 2;
}
Regards,
Valentina
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2017 07:43 AM
Hi Aamir,
I suggest to create a 'before' Business Rule on 'update' of sc_req_item table.
Conditions: State changes to 'Closed'
Script:
var task = new GlideRecord('sc_task');
task.addQuery('request_item', current.sys_id);
task.addActiveQuery();
task.query();
if(task.hasNext()){
gs.addErrorMessage('Please, close all Tasks before to close the Request Item');
}
Hope it helps!
Regards,
Valentina
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2017 08:40 AM
Hi Valentina,
It displays the error message but also updates the state from open to closed.
I tried current.setAbortAction(true);
But no luck. Any idea how to do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2017 08:51 AM
Hi Aamir,
you are right, I missed it, you have to set the state to the previous value as well:
var task = new GlideRecord('sc_task');
task.addQuery('request_item', current.sys_id);
task.addActiveQuery();
task.query();
if(task.hasNext()){
gs.addErrorMessage('Please, close all Tasks before to close the Request Item');
current.state = 2;
}
Regards,
Valentina
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2017 09:28 AM
Thanks. It worked. But used current.state = previous.state; instead of current.state = 2; to make it more dynamic.
Thanks for your help.