Closing a HR case automatically after last task is closed

Thedavisrun
Mega Expert

I have a record producer that creates a HR Case.  This HR case has an associated HR Service which has two tasks tagged on to it.  I would like to set it in a way where when the last task is completed the Hr case is automatically set to closed (or awaiting acceptance).

Is this possible? 

I don´t mind any type of solution but i thought this was something that could be done OOTB with New York.

1 ACCEPTED SOLUTION

Hi,

I believe we can do it in few ways:

1) Async Business rule on task table.

2) Editing and managing workflow.(Bit tricky and might not be good)

3) Use gs.sleep in business rule so that it will run ur code bit late i.e after 3 4 secs.

Thanks,
Ashutosh

View solution in original post

14 REPLIES 14

Hi,

I believe we can do it in few ways:

1) Async Business rule on task table.

2) Editing and managing workflow.(Bit tricky and might not be good)

3) Use gs.sleep in business rule so that it will run ur code bit late i.e after 3 4 secs.

Thanks,
Ashutosh

I used the async as the BR type and and it sorted the problem.  Thank you very much for your help!!

Below Business rule can be implemented for this requirement
Condition: Aysnc Update
Filter Could Be: HR service which you have created for Lifecycle Event and state changes to Close Complete
Table: sn_hr_core_task

You need to check the activity set context if the trigger condition is different for the activity sets otherwise it will close the case without checking the activity set status. 

This Business rule will check that all mandatory task is completed then it will close the case. You can modify the query as needed, also gs.sleep() will not work in scoped application, hence custom script is written to wait for 5 sec so that context can be updated.

(function executeRule(current, previous /*null when async*/ ) {

    //current = HR Task 
    var grSiblingsHRTask = new GlideRecord('sn_hr_core_task');
    grSiblingsHRTask.addQuery('parent', current.parent);
    grSiblingsHRTask.addQuery('optional', false);
    grSiblingsHRTask.addActiveQuery();
    grSiblingsHRTask.query();

    var endSleep = new GlideDuration().getNumericValue() + 5000;
    while (new GlideDuration().getNumericValue() < endSleep) {
        //wait for 5 sec
    }

    var activitystatus = new GlideRecord('sn_hr_le_activity_set_context');
    activitystatus.addQuery('hr_case', current.parent);
    activitystatus.addEncodedQuery('stateINawaiting_trigger,running_activities,faulted');
    activitystatus.query();


    if (!grSiblingsHRTask.next() && !activitystatus.next()) {
        var grHRCase = new GlideRecord('sn_hr_core_case');
        if (grHRCase.get(current.parent)) {
            grHRCase.state = 3;
            grHRCase.work_notes = "Case closed as all mandatory tasks are completed";
            grHRCase.update();
        }
    }

})(current, previous);

 

asifnoor
Kilo Patron

Hi,

you can do this using workflow, without any coding required.

Create the tasks in the workflow and once the 2nd task is closed, mark the hr_case closed.

Mark the comment as a correct answer and hepful if it helps.

Thank you for this response @asifnoor !