How to assign an user for approval by using script in workflow in run script

siddharth29
Mega Contributor

Hi,

can any one guide how to assign an approver by using script in work flow(run script)

I had written some code, pls check and tel me if am wrong

var desc = task.description;

var startDate = current.variables.colleague_start_date;

if(startDate != null && startDate != ''){

    task.description = "Colleague Start Date: " + startDate + "\n\n" + desc;  

}

  if(current.variables.u_emp_site == "u_hgstsz" && current.variables.u_items == "u_laptop")

  {

  current.sysapproval_approver.approver= "0526160bb4c6f500b47b0c26378dccee";

}

1 ACCEPTED SOLUTION

guhann
Mega Guru

1) Create a IF conditional activity to check the condition



answer = ifScript();


function ifScript() {


  if (current.variables.u_emp_site == "u_hgstsz" && current.variables.u_items == "u_laptop") {


              return 'yes';


    }


    return 'no';


}



2) Then connect the Yes flow to an Approval User activity in your workflow with below code in it to generate approval to a specific user.,


answer = [];


answer.push('0526160bb4c6f500b47b0c26378dccee'); // sys_id of the user.


View solution in original post

28 REPLIES 28

Untitled.png


pls find the screen shot, requirement is like if user selects


(1)HGSP-laptop-request should go to approver1


(2)HGST SZ-laptop-request should go to approver2


(3)HSPC -laptop-request should go to approver3


(4)HGSP-Hardware-request should go to approver4


(5)HGST SZ-Hardware-request should go to approver5


(6)HSPC-Hardware-request should go to approver6




like that based upon the "site" field selection and below check box selection the approver will change.


hope u got it pls suggest me


Hi Pradeep,



Can u check this once.


Have you also created a field for storing the approver in the custom table? if not pls create a reference field named 'u_approver' referencing the sys_user table and store the appropriate approver for each combinations. Then try the below script,



answer = [];


var gr = new GlideRecord('u_it_service_request_nrp');


gr.addQuery('u_emp_site',current.variables.u_hgstsz);


gr.addQuery('u_item',current.variables.u_laptop);


gr.query();



if(gr.next()) {


answer = gr.u_approver;


}


Hi guhan,


yes i have created the table with user table reference approval only pls find the screen shot of the table format, and i updated details manually. thank you.Capture.PNG


Okay.. Then just try the code I gave in my previous response. It should work. Ensure all the variable names are correct.



Please mark the response as helpful/correct answer as appropriate.