- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016 01:34 AM
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";
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016 01:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016 01:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016 01:59 AM
Hi guhan
Actually there are 40 around conditions in that u_emp_site & current.variables.u_items variables, so i cant create user approval activity 40 in work flow so i am planning to create in run script, kindly suggest on the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016 02:07 AM
Okay. Since you have 40+ combinations to decide the approver I would suggest you to have a custom table created to store those combinations and in the 'Approval User' activity script, do a gliderecord on this table to get the approver and push it to answer object.
Do let me know if you need any help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016 02:17 AM
Create a table with fields like
Emp Site
Item
Approver (Reference to sys_user)
Then in the Advanced Script section of Approval User activity have the below code,
answer = [];
var gr = new GlideRecord('table_name');
gr.addQuery('u_emp_site',current.variables.u_emp_site);
gr.addQuery('u_item',current.variables.u_items);
gr.query();
if(gr.next()) {
answer = gr.u_approver;
}