How to define dynamic approval creation using approval activity in workflow.

Koyel Guha
Tera Contributor

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. 

 

KoyelGuha_0-1687434737646.png

 

8 REPLIES 8

Hi @Ankur Bawiskar , How to mention two individual approvers so that if anyone of the approver approves, it proceeds the next step. Could you please confirm this ?

 

if(gs.getUser().getUserByID(workflow.scratchpad.approver).isMemberOf('Group'))
{
answer = ['4f7a90c9dbb5a700ce59a155059619c6', '8df91445dbb5a700ce59a15505961922'];
}

 

@Koyel Guha 

that is defined in workflow activity

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/administer/workflow-activities/refe... 

AnkurBawiskar_0-1687451443696.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Koyel Guha
Tera Contributor

Thank You for your help @Ankur Bawiskar . It is working now. 

 

@Koyel Guha 

Glad to help.

Please mark my response as correct and close the thread.

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