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

Luxo Nadappan
Tera Guru

hi ,

please create business rule  for the same, You can look in community for something  same related with RITM and catalog task ... 

Thanks

Luxo 

Hi Luxo,

i´ve tried with a BR but can´t seem to get it working.  Could you take a look?

I created a Business rule on the HR core case table.  The condition is for cases with a  specific Hr Service. 

I have a record producer that i test with that opens a case with that HR service and 1 task.  when i close the task as completed it goes to active false.  but the HR case state does not change.find_real_file.png

The script I put in advanced is the below.

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

var total_task = getTotalTask(); // Get Total Number of Tasks related to HR Case
var close_task = getClosedTask(); // Get Total Closed Tasks related to HR Case

function getTotalTask(){

var gr = new GlideRecord('sn_hr_core_task');
gr.addQuery('sn_hr_core_case', current.sys_id);
gr.query();
return gr.getRowCount();
}

function getClosedTask(){

var gr = new GlideRecord('sn_hr_core_task');
gr.addQuery('sn_hr_core_case', current.sys_id);
gr.addQuery("active", false);
gr.query();
return gr.getRowCount();
}

var hrCase = new GlideRecord('sn_hr_core_case');
hrCase.addQuery("sys_id", current.sys_id);
hrCase.query();

if (change.next()) {

if(total_task == close_task)
{
hrCase.state = 20 ;
}
}
hrCase.update();
}
)(current, previous);

 

hi ,

Please create a Before business rule in the task table and use the same logic to look for related Case..then  update the state... 

Thanks

Luxo 

Chaitanya Redd5
Tera Guru

Hi,

You need to create Business Rule on HR Task(sn_hr_core_task) table and below is the script which you can use to close the HR Case(sn_hr_core_case) on the closure of last HR Task.

Business Rule:

Table: sn_hr_core_task

When: After - Update

Filter: Active Changes To False

(function executeRule(current, previous /*null when async*/) {
	var hrtask = new GlideRecord('sn_hr_core_task');
	hrtask.addQuery('field_name_which_shows_hr_case',current.field_name_which_shows_hr_case);
	hrtask.addActiveQuery();
	hrtask.query();
	if(!hrtask.next()){
		var hrcase = new GlideRecord('sn_hr_core_case');
		hrcase.addActiveQuery();
		hrcase.addQuery('sys_id',current.field_name_which_shows_hr_case);
		hrcase.query();
		if(hrcase.next()){
			hrcase.setValue('state',20);
			hrcase.update();
		}
	}
})(current, previous);

 

NOTE: Replace all "field_name_which_shows_hr_case" from script to the actual field name on HR task table where the HR Case is displayed.

Kindly Mark my answer as Correct/Helpful based on the impact.

Regards,

Chaitanya