- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2019 07:16 AM
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 )
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2019 08:30 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2019 12:06 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2019 12:09 PM
that is weird. There has to be something on sc_task, sc_req_item or task table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2019 12:09 PM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2022 10:05 AM
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;
}