How to close the parent hr case automatically when all the HR Tasks are closed.

Austin17
Tera Contributor

Hi All - 

I am trying to automatically close an HR0 Case with a particular service when all the associated HR Tasks are closed. I have tried the following After Business Rule, along with some others, but they all have the same result.

 

    (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 hrcase = new GlideRecord('sn_hr_core_case');
    hrcase.addActiveQuery();
    hrcase.addQuery('sys_id',current.parent);
    hrcase.query();

    if(hrcase.next()){
    hrcase.setValue('state',3);
    hrcase.update();
    }
    }
    })(current, previous);

 

For this particular service, we have tasks that are assigned to the Subject Person and their manager. With this script however, it closes the HR Case when the Managers tasks are closed and the Subject Persons are still in a Ready state. Does anyone have any idea why this would be or have any other ways they have achieved this? Thanks

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I have shared solution below using flow designer to close parent INC when all child INCs are closed.

Enhance it for your sn_hr_core_task and sn_hr_core_case table

If all child incident is closed then after Parent incident should be closed. How to achieve through...

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I have shared solution below using flow designer to close parent INC when all child INCs are closed.

Enhance it for your sn_hr_core_task and sn_hr_core_case table

If all child incident is closed then after Parent incident should be closed. How to achieve through...

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Easy enough! Thank you for sharing your solution, this did the trick. 

Glad to help.

Please mark response helpful as well.

Stay safe.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader