How to define dynamic approval creation using approval activity in workflow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2023 04:53 AM - edited ‎06-22-2023 04:54 AM
Hi ,
I am facing issue to define dynamic approval in the approval activity. Please find the code.
workflow.scratchpad.approver is storing username and is defined in the runscript of the wf. If workflow.scratchpad.approver is a member of the below group, then it would go to 2 approvers. else the approval will go the variable as mentioned as primary owner.
For the below, the approval is getting skipped.
//--------------- For Item XXXXXXX ------------------
else if (item == "XXXXXXX") {
if(workflow.scratchpad.approver.isMemberOf('Group'))
{
answer = ['4f7a90c9dbb5a700ce59a155059619c6', '8df91445dbb5a700ce59a15505961922'];
}
else {
if (workflow.scratchpad.request_type == "create" || workflow.scratchpad.request_type == "delete") {
answer = [current.variables.primary_owner];
} else {
var answer = [];
answer.push(current.variables.primary_owner);
answer.push(current.variables.new_primary_owner);
}
}
}
Could you please help me with the above code so that the approval goes to the mentioned sysids else primary owner.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2023 05:14 AM
this will work; use this line
if(gs.getUser().getUserByID(workflow.scratchpad.approver).isMemberOf('Group'))
{
answer = ['4f7a90c9dbb5a700ce59a155059619c6', '8df91445dbb5a700ce59a15505961922'];
}
else {
if (workflow.scratchpad.request_type == "create" || workflow.scratchpad.request_type == "delete") {
answer = [current.variables.primary_owner];
} else {
var answer = [];
answer.push(current.variables.primary_owner);
answer.push(current.variables.new_primary_owner);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2023 07:29 AM
Hi @Ankur Bawiskar ,
The approvals are going to the mentioned sysids .However, it should proceed if one of the approver approves the request. But it is asking for both the approvals then processing the next step .
I have 2 approvers from different groups. Can we do something so that it would work dynamically and send the approvals to both instead of putting sysids to avoid the manual approach. so that in future if the approver names get changed , there is no need to put sysid.
is it possible ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2023 08:04 AM
So the script I shared is working fine.
Please mark my response as correct as my approach worked for you.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2023 08:05 AM
it depends on what have you configured in the approval activity i.e. anyone approves or all approves etc
to make it dynamic you can store those sysIds in system property and then use that in your workflow script
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader