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-16-2022 08:13 AM
You can accomplish this with a Client Script (onChange of State field) and Script Include.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue==3) { //Closed Complete
var ga = new GlideAjax('HRScriptInclude');
ga.addParam('sysparm_name', 'validateChildTasks');
ga.addParam('sys_id', g_form.getUniqueValue());
ga.getXML(setValues);
}
function setValues(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if(answer == "true") {
g_form.addErrorMessage(gs.getMessage("hr_open_tasks_exist"));
g_form.setValue('state',oldValue);
} else {
g_form.setValue('state',newValue);
}
}
}
Script Include Function
validateChildTasks: function(){
var sys_id = this.getParameter('sys_id');
var flag = false;
var taskRec = new GlideRecord('task');
taskRec.addQuery('parent', sys_id);
taskRec.addActiveQuery();
taskRec.query();
while (taskRec.next()) {
flag = true;
}
return flag;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 03:38 AM
Hi Sbritt,
we have tried this option and it is showing error message correctly but case state is changing to Resolved state. Please suggest.
Thanks,
Jyoti

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 04:07 AM
The example code is only checking for changing to Closed Complete, so you can update it to include any other values like Resolved also.
if(newValue==3) { //Closed Complete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 05:10 AM
I have updated the newvalue == 20 // resolved state but still it is changing the state.