HR case should not closed if any HR task is open

Jyoti Mehta
Tera Contributor

Hi,

we have an requirement where a HR case should not be closed until all the HR tasks will be completed. For which we have created a onbefore business rule whenever case state changes to Resolved state then it should be abort and show error message.

we are facing issue for the error message : Here case is abort when click on resolved button but it is not showing the error message. Can anyone please check below script and suggest ?

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

var gr = new GlideRecord('sn_hr_core_task');
gr.addActiveQuery();
gr.addQuery('parent',current.sys_id);
gr.query();
if (gr.next()) {
// gs.addInfoMessage("please close HR tasks first");
gs.addErrorMessage(gs.getMessage('please close HR tasks first'));
current.setAbortAction(true);
}

})(current, previous);

13 REPLIES 13

Hi Jaspal,

Here we have to add this functionality only for HR Situation Management Cases, not for HR core case due to which I am not doing any changes in UI action.

Thanks,

Jyoti 

Jyoti Mehta
Tera Contributor

Hi All,

Thanks for your response! I will try these options and let you know.

Regards,

Jyoti 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

the script looks fine to me.

Also it has worked for John.

Regards
Ankur

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

shloke04
Kilo Patron

Hi @Jyoti Mehta 

There might be a possibility that on your Task form the Active field might not be getting set correctly when you close a Task .

So instead of using AddActiveQuery in your BR, try evaluating the state of Task field and use the modified script as below:

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

var gr = new GlideRecord('sn_hr_core_task');
gr.addQuery('parent',current.sys_id);
gr.addEncodedQuery('state!=3');
gr.query();
if(gr.next()) {
// gs.addInfoMessage("please close HR tasks first");
gs.addErrorMessage(gs.getMessage('please close HR tasks first'));
current.setAbortAction(true);
}

})(current, previous);

Please try this and let me know the outcomes how it goes.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke