HR case should not closed if any HR task is open
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 07:59 AM
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);
- Labels:
-
Case and Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 03:40 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 11:58 PM
Hi All,
Thanks for your response! I will try these options and let you know.
Regards,
Jyoti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 03:44 AM
Hi,
the script looks fine to me.
Also it has worked for John.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 07:14 AM
Hi
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
Regards,
Shloke