RITM should be closed incomplete, When any one SCTASK is closed incomplete or closed skipped?

suresh40
Tera Contributor

Hi Team,

The Requested item should not closed complete without all SCTASK is completed. If user try close Requested item without closing all SCTASK give an error message and revert back to the pervious state. Its is working fine.

I'm using script :

Before Update on sc_req_item

Condition:   State [IS] Closed Complete 

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

var gr = new GlideRecord("sc_task");
gr.addActiveQuery();
gr.addQuery("request_item", current.sys_id);
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage("Please close all Sc Tasks and then close RITM");
current.setAbortAction(true);
}

})(current, previous);

Now my requirement is If any one  SCTASK is closed incomplete or closed skipped , Ritm state should be closed in complete . Can we applicable in the same Business rule.

Like If have 3 SCTASK, manually one task changes to closed complete state , 2nd task changes to closed incomplete state , 3rd task changes to closed skipped RITM Should state should be Closed Incomplete.

IF all task changes closed complete means RITM state also changes automatically closed complete . If any SCTASK state is closed incomplete or closed skipped , RITM state should be Closed incomplete. Please help me on this .

Thanks 

Suresh

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

You can handle this in the workflow of each Catalog Item that it applies to by adding the Closed Complete, Closed Incomplete, and Closed Skipped conditions to each Catalog Task activity.  You could also accomplish this with an after Update Business Rule on the sc_task table with the Filter Conditions State is one of Closed Incomplete Closed Skipped.  Your script on the Advanced tab would look like this.

(function executeRule(current, previous /*null when async*/) {
	var ritm = new GlideRecord('sc_req_item');
	ritm.addQuery('sys_id', current.request_item);
	ritm.query();
	if (ritm.next()) {
		ritm.state = 4; // Closed Incomplete
		ritm.update();
	}
})(current, previous);

In your scenario the workflow would never make it to the 3rd task as the 2nd was Closed Incomplete, which would update the RITM to Closed Incomplete, which automatically cancels the workflow.

If you want to wait until the RITM is attempted to Close Complete to do this check, that could work too.  Your combined BR script would look like this.

(function executeRule(current, previous /*null when async*/) {
	var gr = new GlideRecord("sc_task");
	gr.addQuery("request_item", current.sys_id);
	gr.query();
	while (gr.next()) {
		if (gr.active == true) {
			gs.addErrorMessage("Please close all Sc Tasks and then close RITM");
			current.setAbortAction(true);
		}
		
		if (gr.state == 4 || gr.state == 7) { // Closed Incomplete, Closed Skipped
			current.state = 4; // RITM Closed Incomplete
		}
	}
})(current, previous);

In either case you can add Filter Conditions or in the script so that this only applies, or doesn't apply to certain Catalog Items.

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

You can handle this in the workflow of each Catalog Item that it applies to by adding the Closed Complete, Closed Incomplete, and Closed Skipped conditions to each Catalog Task activity.  You could also accomplish this with an after Update Business Rule on the sc_task table with the Filter Conditions State is one of Closed Incomplete Closed Skipped.  Your script on the Advanced tab would look like this.

(function executeRule(current, previous /*null when async*/) {
	var ritm = new GlideRecord('sc_req_item');
	ritm.addQuery('sys_id', current.request_item);
	ritm.query();
	if (ritm.next()) {
		ritm.state = 4; // Closed Incomplete
		ritm.update();
	}
})(current, previous);

In your scenario the workflow would never make it to the 3rd task as the 2nd was Closed Incomplete, which would update the RITM to Closed Incomplete, which automatically cancels the workflow.

If you want to wait until the RITM is attempted to Close Complete to do this check, that could work too.  Your combined BR script would look like this.

(function executeRule(current, previous /*null when async*/) {
	var gr = new GlideRecord("sc_task");
	gr.addQuery("request_item", current.sys_id);
	gr.query();
	while (gr.next()) {
		if (gr.active == true) {
			gs.addErrorMessage("Please close all Sc Tasks and then close RITM");
			current.setAbortAction(true);
		}
		
		if (gr.state == 4 || gr.state == 7) { // Closed Incomplete, Closed Skipped
			current.state = 4; // RITM Closed Incomplete
		}
	}
})(current, previous);

In either case you can add Filter Conditions or in the script so that this only applies, or doesn't apply to certain Catalog Items.

Hi Brad Bowman,

 

Thanks for your help. Its working fine.