Dynamic Approval Group Scripting

chrish5
Giga Guru

I need to have the approval group in my workflow be dynamic based on what the users selects from a request form field.   Here are the details.     My request form has a lookup select box called Location (location) that is referring a table holding all my locations.     I am using a BR to copy the selected location to a table column called Shuttle Location (shuttle_location).   I have a workflow associated with this request form with a group approval and this approval has to vary depending on the location is selected.   Each location has its own approval group.   And there are dozens of locations, thus the need to do this dynamically.   I could build this in the workflow with a switch flowing to all the different approvals, but that would be ugly and not very maintainable since locations will change.   I've tried using the below script to make this approval group dynamic, but I keep getting an error that "shuttle_location" is not defined.   Is this switch script the correct way to do this?   Should it be referencing the form variable location rather than the table column shuttle_location that I am copy location to?  

var answer = [];

switch(shuttle_location){

case 'nebraska city':

  1. answer.push('Shuttle - Nebraska City');

break;

case 'new rockford':

  1. answer.push('Shuttle - New Rockford');

break;

case 'jamestown':

  1. answer.push('Shuttle - Jamestown');

break;

case 'amarillo':

  1. answer.push('Shuttle - Amarillo');

break;

default:

  1. answer.push('Default Approvers');

}

1 ACCEPTED SOLUTION

Please mark answer as correct.



Regards,


Sachin


View solution in original post

21 REPLIES 21

Shishir Srivast
Mega Sage

I believe it should be form variable location, can you please try with


current.variables.shuttle_location



Also, in you code not sure what is the purpose of a.answer.push(), i think you can directly use answer.push()


Hi Shishir,


I've tried current.variables.shuttle_location and current.variables.location and both give me an error.     Ignore the a.answer.push().   That came across wrong in the cut/past into this posit.     It is correct as answer.push().  


sachin_namjoshi
Kilo Patron
Kilo Patron

Please use below code



var answer = [];



switch(current.variables.shuttle_location.toString()){


case 'nebraska city':


  1. answer.push('Shuttle - Nebraska City');

break;case 'new rockford':


  1. answer.push('Shuttle - New Rockford');

break;case 'jamestown':


  1. answer.push('Shuttle - Jamestown');

break;case 'amarillo':


  1. answer.push('Shuttle - Amarillo');

break;default:


  1. answer.push('Default Approvers');

}



Regards,


Sachin


I tried that.   No error, but it is just going thru and not assigning an approval group.