Auto closing of work order when multiple work order tasks are assigned to different vendors

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 07:15 AM
We have 2 scenarios.
Scenario 1 - When there are multiple WOT assigned to the same vendor group, then, only when all WOT are closed then only WO gets closed.
But we are facing issue with this following
Scenario 2 - When multiple WOT are assigned to the different vendor groups and if we close any one WOT of them, then, WO gets closed automatically. It's not checking if other WOT are closed or not.
Is this expected behavior? OR are we missing anything in the script? We tried to change the logic of the script, but it didn't give us required output.
Please suggest.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 07:27 AM
I doubt anyone can help with your script logic since no details are provided. Such as type of script (business rule, client script, etc.) and the actual script itself.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 10:30 PM
Here is the script
var wmTask = new GlideRecord('wm_task');
wmTask.addQuery('parent', current.parent); //current.parent
wmTask.query();
var allClosed = true;
while (wmTask.next()) {
if (wmTask.state != 3) {
allClosed = false;
break;
}
}
if (allClosed) {
gs.log("inside else if");
var wmOrder = new GlideRecord('wm_order');
wmOrder.get(wmTask.parent); //current.parent
wmOrder.state = 3;
wmOrder.work_notes = 'Automatically Wo closed as WOT closed .';
wmOrder.update();
var case1 = new GlideRecord('sn_customerservice_case');
case1.get(wmTask.parent.parent); //wmOrder.parent
case1.state = 3;
case1.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 07:17 AM - edited 09-06-2024 03:02 PM
The code looks like it is from a business rule. What table is that defined on? Anyway, you can try the following changes and test. check debug output in Script log statements, search message, starts with, "BR:"
var wmTask = new GlideRecord('wm_task');
wmTask.addQuery('parent', current.parent); //current.parent
wmTask.query();
// Find all wm task records that are children
var allClosed = true;
while (wmTask.next()) {
gs.info('BR: Checking wm_task: ' + wmTask.number + ', state = ' + wmTask.state);
if (wmTask.state != 3) {
allClosed = false;
break;
}
}
gs.info('BR: allClosed = ' + allClosed);
// If all tasks are closed, then close the parent work order
if (allClosed) {
gs.info("BR: inside allClosed, checking work orders for parent: " + current.number);
var wmOrder = new GlideRecord('wm_order');
// wmOrder.get(wmTask.parent); //current.parent (since while loop has a break statement)
// check for record exists
var childWO = wmOrder.get(wmTask.parent); //current.parent
// update WO if found
if (childWO) {
gs.info("BR: Found child work order to close: " + wmOrder.number);
wmOrder.state = 3;
wmOrder.work_notes = 'Automatically Wo closed as WOT closed .';
wmOrder.update();
}
// Now check for a parent Case record
var case1 = new GlideRecord('sn_customerservice_case');
// case1.get(wmTask.parent.parent); //wmOrder.parent
var parentCase = case1.get(wmOrder.parent,parent); //wmOrder.parent
// check for record exists
if (parentCase) {
gs.info("BR: Found parent case to close: " + casel.number);
case1.state = 3;
case1.update();
}
}
I don't see any obvious problems other that assuming a parent record exists when you use GlideRecord get() method.
I don't know how to test, the state field is read-only on my wm_order records. Some application process is involved it seems to progress the state.