Abort RITM closure if work order or work order task is active
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 07:27 AM
Hi,
I have a requirement that if user directly closing the RITM, system will check if there is any active work order or active work order task for that work order is there or not.
If yes, then system will abort closing the RITM.
I have created a before business rule with condition, state changes to closed complete and used below script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 10:00 AM
I would keep the two GlideRecords separate, as there is nothing gained by combining them:
(function executeRule(current, previous /*null when async*/ ) {
var rec = current.sys_id;
var gr = new GlideRecord('wm_order');
gr.addQuery('initiated_from', rec);
gr.addQuery('active', true);
gr.query();
if (gr.next()){
current.setAbortAction(true);
gs.addErrorMessage('Please close the related active work order to close the RITM');
}
var ga = new GlideRecord('wm_task');
ga.addQuery('initiated_from.parent', rec);
ga.addQuery('active', true);
ga.query();
if (ga.next()) {
current.setAbortAction(true);
gs.addErrorMessage('Please close the related active work order task to close the RITM');
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 12:17 AM
Hi Brad,
Thanks for your update. I can do that but the requirement is to show only one error message. In the above script system will show two error message every time.
So for that I want to merge both work order and work order task. Can you help me if I did anything wrong on my script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 05:46 AM
Since you can't/won't ever have an active work order task without an active work order, this makes more logical sense:
(function executeRule(current, previous /*null when async*/ ) {
var rec = current.sys_id;
var gr = new GlideRecord('wm_order');
gr.addQuery('initiated_from', rec);
gr.addQuery('active', true);
gr.query();
if (gr.next()) {
var ga = new GlideRecord('wm_task');
ga.addQuery('initiated_from.parent', rec);
ga.addQuery('active', true);
ga.query();
if (ga.next()) {
current.setAbortAction(true);
gs.addErrorMessage('Please close the related active work order task to close the RITM');
}
} else {
current.setAbortAction(true);
gs.addErrorMessage('Please close the related active work order to close the RITM');
}
})(current, previous);