Approval Wait for Condition Stuck and will not move forward

Tony Landowski
Kilo Contributor

I have the below Wait for condition that I am trying to find out why it will not move forward to the next step of the workflow.  Can someone please help.  Note: the need is to wait for both approvals before moving to the next step.

 

Script:

var rec = new GlideRecord('sysapproval_approver');
rec.addQuery('sysapproval', current.sys_id);
rec.addQuery('active', true);
rec.query();
if(rec.hasNext()){
answer = false;
}
else{
answer = true;
}

 

Workflow:

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Your workflow is on RITM table but the actual update will happen on Approval table.

So workflow won't know when to process the wait for condition.

Wait for condition is processed when update happens on that record in this case RITM

So workaround is create after update BR on sysapprovap_approver table and mimic the update on RITM record so that workflow evaluates the condition and proceeds if all approvals are done

Condition: current.sysapproval.cat_item.name == 'Your Catalog Item Name Here' && (current.state == 'approved' || current.state == 'rejected')

Script:

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

	// Add your code here

var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id',current.sysapproval);
gr.query();
if (gr.next()) {
 new Workflow().broadcastEventToCurrentsContexts(gr, 'update', null);
}


})(current, previous);

Also update your wait for condition script as below

answer = false;

var rec = new GlideRecord('sysapproval_approver');
rec.addQuery('sysapproval', current.sys_id);
rec.addQuery('state', 'requested'); // check if any approval for this RITM is in requested state
rec.query();
if(!rec.next()){
answer = true; // if not found then proceed

}

Regards
Ankur

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

View solution in original post

6 REPLIES 6

Tony Landowski
Kilo Contributor

Thank you both, very helpful.  

@Tony Landowski 

Glad to help.

If my response helped you please mark my response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

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