how to add approver in workflow depending on selection of user of a field

aritra23
Kilo Contributor

how to add approver in workflow depending on selection of user for a field like lookup select box?

14 REPLIES 14

gemini17
Kilo Guru

Hey Aritra:



You need to script based on the   table you created for Lookup Select Box.   Modify the following script as per your requirement.   In this case "u-catalog_item_approvers" was the table for my Lookup Select Box.



Approval - User Script:



var answer = [];


var approver = new GlideRecord("u_catalog_item_approvers");


var liststr = current.variables.supervisor.toString();


approver.addQuery('u_name','=', liststr);


approver.query();


while(approver.next()){


answer.push(approver.u_name);



'u_catalog_item_approvers' is a table for 'Look Up Select Box' variable.



Hope this helps.



Hit it Correct, as you see the impact.



Kind regards


Danny Raj


answer='';




var approver= new GlideRecord('sys_user');


var nm =current.variables.manager;


approver.addQuery('name','is','nm');


approver.query();


while(approver.next())


{


answer=''+approver.name;


}



i have written this , but this not working. can you tell me the mistake


Hi Arithra:



I thought, you had a separate look up select box, from which a user selects the approver.   In your script, you are selecting 'sys_user' table!   That may be the problem.   Why don't you create a table, for there are not going to be a whole lot of managers(approvers) to select from, and then script exactly like my script and give it a try.   It worked fine for me.  



Cheers!


P.S.   Mark it correct as you see the impact.



Kind regards


Danny Raj


var answer = [];


var approver = new GlideRecord("u_managers");


var liststr = current.variables.manager;


approver.addQuery('u_user_name','=', liststr);


approver.query();


while(approver.next()){


answer.push(approver.u_user_name);}



its not working any way .
what can be the problem?
i made a different table but then also its not working.


terrykim
Tera Contributor

I hope to make this clear by using an image to show the three components used. (see attached image)   this might make it easier to grasp.


 


The field mu_approver is a reference field .   Top left of the image is the workflow , middle right of the image is the workings inside the approval user object (in the workflow) and bottom left of the image is the catalog item with the variable that is used in the workflow.  


3. variable set within a user catalog item.jpg