Once all the Tasks are closed, RITM and request wil close automatically

SNOW46
Tera Contributor

Hi All,

I want to configure one script for Service Catalog. When all the Tasks are closed, then corresponding RITM as well as Request will get closed automatically.

Incase of any RITM if there is only single task then once the TASK is closed, then RITM State will be updated to Closed Complete as well as Request will also gets closed.

On the another hand, incase of any RITM if there are any multiple TASK generated, then till all the TASK are not closed the RITM state will not change to Closed Complete or get closed.

After all the TASK are closed, the RITM as well as Request will also get Closed.

 

Can anyone let me know how to achieve this requirement.

 

Thanks,

SNOW@Das

18 REPLIES 18

Alikutty A
Tera Sage

 

Hello,

If you are using workflow, then you should set the state/stage of request item to closed/complete from your last workflow activity after all tasks are closed. To close your request, write an after business rule on sc_req_item table when state or stage changes to closed/complete and a script to access the related request and close it.

 

var req = new GlideRecord('sc_request');

if(req.get(current.request)){

req.state = 3;

req.update();

}

Thanks!

suzanneswanson
Kilo Guru

Hi SNOW@Das,

The workflow will handle all of this for you.  There are a couple of places that you need to be aware of.

1. If you have multiple Catalog Task activities on the same RITM, then use a JOIN activity.  All Catalog Task activities should go to the JOIN activity. The JOIN activity will go to the End activity.  This will make sure that all TASKs are complete before closing the RITM.

2. If you have one Catalog Task activity, set the state of the End activity to 'Completed'. This will prevent a premature end.

3. In the Catalog Task activity, there is a checkbox that says, "Wait for completion".  Check this box.  This will prevent the workflow from continuing before the TASK is completed.

I hope this helps.

 

Hi,

Actually can you please let me know to define an Business Rule instead of Workflow. Its an requirement came to me to configure it via script instead of workflow.

 

 

Thanks,

SNOW@Das

You can check this BR. 

 

checkAllClosed();

function checkAllClosed(){
	// Current Catalog Task Item Sys_id
	var catItem = current.sys_id;
	var rest = true;
	
	var catSys = new GlideRecord("sc_task");
	catSys.addQuery("request_item", current.request_item);
	catSys.query();
	while(catSys.next()){
		if(checkActive(catSys.sys_id)==true){
			rest = false;
		}
	}
	// Include the code to rest the state of Req ITEM to Closed Complete
	if(rest==true){
		updateReqItem(current.request_item);
	}
}

function checkActive(catSysID){
	var res = false;
	
	var rec = new GlideRecord('task');
	rec.addQuery('sys_id', catSysID);
	rec.addActiveQuery();
	rec.query();
	if(rec.next()){
		res = true;
	}
	
	return res;
}

function updateReqItem(reqItem){
	
	var rec = new GlideRecord('sc_req_item');
	rec.addQuery('sys_id', reqItem);
	rec.query();
	if(rec.next()){
		rec.state = 3;
		rec.update();
	}
}