- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2020 05:26 AM
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:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2020 06:58 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2020 01:00 PM
Thank you both, very helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2020 09:31 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader