set all other tasks closed incomplete if any one task is closed incomplete.

snow_p
Tera Contributor

Hi,

We have a requirement, where three tasks are triggering at same time and if any one of the task is closed incomplete, I need to set the remaining tasks to closed incomplete and set the RITM to closed incomplete. Do I need to include any run script in workflow or any Business Rules ?

Looking for script suggestions.

 

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use after update BR on sc_task

Condition: State Changes to Closed Incomplete && current.request_item.cat_item.name == 'Your Item Name'

Script: Ensure you give correct state choice value

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

	// Add your code here
	var gr = new GlideRecord("sc_task");
	gr.addActiveQuery();
	gr.addQuery("request_item", current.getValue('request_item'));
	gr.query();
	while(gr.next()) {
		gr.state = 4;
		gr.update();
	}

	var ritm = gr.request_item.getRefRecord();
	ritm.state = 4;
	ritm.update();

})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur, thanks for helping me with the code. The code is working as needed and RITM is set to closed incomplete. But, if any one of the task is closed incomplete, the other two tasks are unable to set to closed incomplete because the assigned to field is mandatory on those two tasks.

How to bypass this assigned to field non-mandatory before setting the tasks to closed incomplete ?

 

 

 

Hi,

then how are you completing task without filling assigned_to?

There must be some data policy which is restricting the closure if assigned to is not empty

2 solutions

1) fill assigned_to with some default user via script and close

OR

2) use setUseEngines(false) to disable data policy

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

    // Add your code here
    var gr = new GlideRecord("sc_task");
    gr.addActiveQuery();
    gr.addQuery("request_item", current.getValue('request_item'));
    gr.query();
    while(gr.next()) {
        gr.state = 4;
        gr.setUseEngines(false);
        gr.update();
    }

    var ritm = gr.request_item.getRefRecord();
    ritm.state = 4;
    ritm.update();

})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur, it worked and the mandatory field is bypassed before setting the task to closed incomplete.

Now, the tasks are set to closed incomplete under RITM but I'm seeing this error on workflow.

find_real_file.png

The 3 tasks are triggering from the branch and upon closing one of the task to closed incomplete, the other two tasks are also set to closed incomplete but showing this error in workflow.