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

Capture.PNG


yes sure already i responded yesterday only on your reply as help full any way i will do now also......... 🙂


Pls see that scrren shot once and guide me


can u hover the Approval - User activity which is in cancelled state and check what is the fault description?


Capture.PNG



pls find the hover scree shot.



thanks


Just replace the script with below one,



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



gs.log('rowCount: '+gr.getRowCount()); // Look for this log in script log statements



if(gr.next()) {


answer.push(gr.u_approver);


}


guhan this is working thank you very much,.



for my know ledge i have this question with out creating table if i wanted to assiggn approver by run scirpt is possible?? by below scirpt



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";



}