Parent case closure based on HR Task closure

Suvetha S
Tera Contributor

I have written a BR in hr task table  to close the parent case once the child HR tasks are getting closed. I have written the below script and instead of changing the state to Close Complete the parent case is getting moved to Awaiting Acceptance state. The backend value of Closed complete is 3 and its not taking the value. 

 

(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.state= '3';
hrcase.work_notes = "Case closed as all to-dos are completed";
hrcase.update();
}
}

})(current, previous);

SuvethaS_0-1666859645475.png

 

1 ACCEPTED SOLUTION

Vinay Mishra3
Mega Guru

Hello @Suvetha S,

Please open the HR service record which and select 'Skip Automatic User Acceptance State' in Case Options field. Below is snapshot for reference. You don't need to make nay change in script.

VinayMishra3_0-1666941572280.png

 

Please mark correct/helpful if it helps you.

Regards,

Vinay

View solution in original post

9 REPLIES 9

Hari haran
Tera Guru

Hi,

Can you please try this script

 

var hrtask = new GlideRecord('sn_hr_core_task');
hrtask.addQuery('parent',current.parent);

hrtask.addQuery('state','!=',3);
hrtask.addActiveQuery();
hrtask.query();

var count = hrtask.getRowCount(); 

if(count==0)

{
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();
}
}

Suvetha S
Tera Contributor

@Hari haran  I tried the above script. Its still the same. Parent case is going to Awaiting Acceptance state

Hi,

Can you please share screenshot of form after task is updated?

SuvethaS_0-1666873850348.png