- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 05:29 AM
Hi All,
I am working on New Hire Onboarding and wanted to close the Parent case to close completed state , once all the child task( which can be HR Task + Request + SR request) , from all different tables get closed , then parent case should get auto closed. But Its not working I have written Business rule on HR Task table and after update BR as below. Can I get any help on this. ?
(function executeRule(current, previous /*null when async*/ ) {
var hrtask = new GlideRecord('sn_hr_core_task');
hrtask.addQuery('parent', current.parent);
hrtask.addActiveQuery();
hrtask.query();
if (!hrtask.next()) {
var reqUpdate = new GlideRecord('sc_request');
reqUpdate.addQuery('parent', current.parent);
reqUpdate.addActiveQuery();
reqUpdate.query();
if (!reqUpdate.next()) {
var sirUpdate = new GlideRecord('sc_request');
sirUpdate.addQuery('parent', current.parent);
sirUpdate.addActiveQuery();
sirUpdate.query();
if (!sirUpdate.next()) {
var hrcase = new GlideRecord('sn_hr_core_case');
hrcase.addActiveQuery();
hrcase.addQuery('sys_id', current.parent);
hrcase.query();
if (hrcase.next()) {
hrcase.state = '3';
hrcase.work_notes = "Case closed as all to-dos are completed";
hrcase.update();
}
}
}
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 04:27 PM - edited 12-21-2023 06:21 PM
Hi @ukti ,
I have modified your code to below and added some comments:
var hrtask = new GlideRecord('sn_hr_core_task');
hrtask.addQuery('parent', current.parent);
hrtask.addActiveQuery();
hrtask.query();
if (hrtask.next()) {
return; // because there is active hr task for the case
}
var reqUpdate = new GlideRecord('sc_request');
reqUpdate.addQuery('parent', current.parent);
reqUpdate.addActiveQuery();
reqUpdate.query();
if (reqUpdate.next()) {
return; // because there is an active REQ for this hr case
}
// Request closure and hr task closure has been checked, close the case
var hrcase = new GlideRecord('sn_hr_core_case');
hrcase.addActiveQuery();
hrcase.addQuery('sys_id', current.parent);
hrcase.query();
if (hrcase.next()) {
hrcase.state = '3';
hrcase.work_notes = "Case closed as all to-dos are completed";
hrcase.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 05:41 AM
Hi,
Please make sure to add logs and track and debug your business rule.
Also make sure all tasks are closed and active=false (there is possibility of some tasks are closed but active is still 'true')
Also check records in respective tables by applying query to verify your query is correct to find completed records.
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 02:18 PM
To make it more scalable, you can just read the task table (HR task, case, request, etc all extend from it and prevents you from having to add other task types if you expand to include finance request, etc) for open records where the parent = onboarding case. However, you'll need to think through the timing of this running. If running on update of any HR Task, then it could run and close the parent onboarding case before all Activity Sets and activities/tasks have even been created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 04:27 PM - edited 12-21-2023 06:21 PM
Hi @ukti ,
I have modified your code to below and added some comments:
var hrtask = new GlideRecord('sn_hr_core_task');
hrtask.addQuery('parent', current.parent);
hrtask.addActiveQuery();
hrtask.query();
if (hrtask.next()) {
return; // because there is active hr task for the case
}
var reqUpdate = new GlideRecord('sc_request');
reqUpdate.addQuery('parent', current.parent);
reqUpdate.addActiveQuery();
reqUpdate.query();
if (reqUpdate.next()) {
return; // because there is an active REQ for this hr case
}
// Request closure and hr task closure has been checked, close the case
var hrcase = new GlideRecord('sn_hr_core_case');
hrcase.addActiveQuery();
hrcase.addQuery('sys_id', current.parent);
hrcase.query();
if (hrcase.next()) {
hrcase.state = '3';
hrcase.work_notes = "Case closed as all to-dos are completed";
hrcase.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 04:29 PM
Hi Ukti,
Also check if this post helps: