workflow is stuck at Approval-User Activity when using wait for : condition based on script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2018 03:41 AM
Hello All,
I have an Requirement:In the "Assess" state of change Request,Approvals will send to the Assignment group Members and Assignment Group Manager.
If the Assignment Group Manager is Approved , then the group members approval is not required.
if anyone of the group member is approved,then the group manager approval is also required.
I added an "Approval user" Activity in the workflow and wrote the script in wait for : condition based on script .
Please observe the below script.
script:
answer = hasAlreadyApprovedLastApproval(current.assignment_group.manager);
function hasAlreadyApprovedLastApproval(managerSysId){
if (JSUtil.nil(managerSysId))
return true;
var grApproval = new GlideRecord('sysapproval_approver');
grApproval.addQuery('document_id', current.getUniqueValue());
grApproval.addQuery('approver', managerSysId);
grApproval.orderByDesc('sys_created_on');
workflow.info("testing manager is:"+ managerSysId);
grApproval.query();
return grApproval.next() && grApproval.getValue('state') === 'approved';
}
}
the above script working as expected but the workflow is not moving to the forward state.
can anyone please help me on this this.
Please observe the attached snapshots
Regards,
Robin
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2018 05:00 AM
Hi Robin,
In the wait for script for approvals I'm pretty sure the answer always needs to be either 'approved' or 'rejected'.
The first part where you return true could be causing problems and I think you should probably return approved instead (if it just automatically approves) or write a different script based on the group membership.
For the rest of the script, I think you could change your return line so that it looks at the state. At that point you could write a simple if statement.
while(grApproval.next(){
if(grApproval.state == 'approved'){
return 'approved';
}
}
That way you verify that you have the approval. Are there any states where the change should be rejected? I think you will need to write that into your script as well. You could add an else if in the above if statement for the rejected case (assuming it uses the managers approval).
Hope that helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2018 05:32 AM
Simply, you can add the group name in the approval user activity and you can configure anyone to approve. So that if either group member or manager approves, it will be processed to next level