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

Hi Guhan,



thank you very ,much for your support, as u guided i have created an custom table and created an approval group in that i had written script in advanced script as below, also pls find the screen shot of my work flow and scirpt below.


Untitled.png


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.Ping Zhou;


}




please tell me if i am anything wrong


Hi Prabhakar,



Can you try the below script once. Just make sure that your variables names are correct.



//Initialize an answer array to be returned


var 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();


while(gr.next()){


  answer.push(gr.Ping Zhou); //Please make sure that Ping Zhou is the exact name of the catalog variable


}



Hi pradeep,



Ping Zhou is the user name need to assign for approval


Little confused. So you want to hard code the user for approval?


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)HGST SZ-laptop-request should go to approver3


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


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


(6)HGST SZ-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