workflow should wait until all the tasks are completed

RudhraKAM
Tera Guru

Hello I have a workflow which is creating 2 tasks up on firing , but if one task is closed another task is marked closed in complete , , i searched in community , they mentioned to use wait for WF event , but not sure what to select in that 

I added Wait for completion on both tasks . 

 

there is another scenario where only 1 task will be created , then how to address that , If i use the wait for WF event then as it will be waiting for another task to complete (which is not going to happen as the condition is not satisfied ) 

find_real_file.png

 

 

find_real_file.png

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.getValue('sys_id'));
rec.addQuery('state','NOT IN','3,4,7');
rec.query();
if(rec.hasNext()){
answer = false;
}
else{
//Continue
answer = true;
}

View solution in original post

23 REPLIES 23

RudhraKAM
Tera Guru

there is a BR running on CHange table which is some how changing this to cancelled ,,tried to inactivate the BR then the set values  is fine but end is showing the cancelled message

find_real_file.png

that is weird. There has to be something on sc_task, sc_req_item or task table.

RudhraKAM
Tera Guru

This is the BR code

 

(function executeRule(current, previous /*null when async*/) {
	
	var source_script = 'Close Parent Epic Order Guide Cat Task';
	var parent = current.parent.getRefRecord();
	var openSiblings = countActiveSiblings(current, parent);
	var retWorkNotes = '';
	updateParent(current, parent, retWorkNotes, openSiblings);
	
	function updateParent(_objCurrent, _objParent, _workNotes, _sibs) {
			
		//when all sibling tasks are closed, map child state to parent
		if (_sibs == 0){
			
			child_state = _objCurrent.state;
			parent_state = _objParent.state;
			
			//CHG is state "Complete Awaiting PV", set parent to "Closed Complete"
			parent_state = child_state == 5 ? 3 : parent_state;
			
			//CHG is state "Closed Complete", set parent to "Closed Complete"
			parent_state = child_state == 6 ? 3 : parent_state;
			
			//CHG is state "Cancelled", set parent to "Closed Incomplete"
			parent_state = child_state == 7 ? 4 : parent_state;
			
			//CHG is state "Closed - Awaiting PIR", set parent to "Closed Complete"
			parent_state = child_state == 8 ? 3 : parent_state;
			
			_objParent.state = parent_state;
			
			//if the parent assigned to person is empty, set to current assigned to.
			_objParent.assigned_to = !_objParent.assigned_to ? _objCurrent.assigned_to : _objParent.assigned_to;
			
			_objParent.update();
			
		}
		
	}
	
	function countActiveSiblings(_objCurrent, _objParent) {
		
		var myParentID = _objParent.sys_id;
		var thisRecord = _objCurrent;
		var thisRecordID = thisRecord.sys_id;
		var thisTable = thisRecord.getTableName();
		var grSiblings = new GlideAggregate(thisTable);
		var numberCount = 0;
		var qryStr = "parent=" + myParentID + "^stateNOT IN5,8,6,7";

		grSiblings.addEncodedQuery(qryStr);
		grSiblings.query();
		numberCount = grSiblings.getRowCount();

		return numberCount;
		
	}
	
})(current, previous);

 

 

Sudeepta
Tera Contributor

For enhancement record to be checked,

1. Put the conditions accordingly

2. var rec = new GlideRecord('rm_enhancement');
rec.addQuery('parent', current.getValue('sys_id'));
rec.addQuery('state','NOT IN','3');
rec.query();
if(rec.hasNext()){
answer = false;
}
else{
//Continue
answer = true;
}