How to close parent record when all child records are completed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 08:10 AM
I'm using the script below to query all associated child work order records by the parent request item record. My goal is to automatically close the request item once all associated records are closed. The problem I'm running into is that the request item is closing as soon as you close one child record. Would anyone have any recommendations on how I can fix this business rule:
Conditions: Status 'Changes To' Completed.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var wo = new GlideRecord("u_navision_sales_order");
wo.addQuery("u_request_item", current.u_request_item);
wo.orderBy('sys_created_on');
wo.query();
while (wo.next()) {
if (wo.u_status != 1 || wo.u_status != 2 || wo.u_status != 3 || wo.u_status != 4 || wo.u_status != 6) {
var req = new GlideRecord("sc_req_item");
req.addQuery("number", current.u_request_item);
req.addQuery('state', 'IN', '1 , 2');
req.query();
if (req.next()) {
req.state = '3';
req.update();
}
}
}
})(current, previous);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 10:04 AM
Thanks Suseela,
Unfortunately this is changing the parent ritm when only one of the child tasks are closed. I wanted the parent ritm to only close when all of the child tasks are closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 04:13 AM
Have you updated the below line with the completed status value
wo.addQuery("u_status", '!=', <<status value>>); //replace with completed value
Or use encodedQuery to check the opened child records.
wo.addEncodedQuery("u_status!=<<status value>>");// update the completed status value
If I have answered your question, please mark my response as correct and/or helpful.
Thanks,
Suseela P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 04:53 AM
Hi mkdj12,
you can go through the following link :
Let me know if I have helped you.
Hope this helps you.
Regards,
Pooja Yadav