How to modify a workflow to add an approver which is entered on a reference variable

yonathanperez
Kilo Contributor

I have an item on the service catalog that contains a reference variable called "Line Manager". I need to modify the workflow, so an activity can be included to create a task for the "Line manager" to approve the request.

1 ACCEPTED SOLUTION

I see it now. You are running that workflow on the request table and not the Request Item as I thought. That is why the activity is being skiped. Please add the following script on the approval activity and let me know if it works (Might need to work further):



//Begin Script


answer = [];


var item = new GlideRecord('sc_req_item');


item.addQuery('request', current.sys_id);


item.query();


while (item.next()) {


if( (item.variables.line_manager   !=   '') {


    answer.push(item.variables.line_manager.sys_id);


}


}


//End Script


Note: If it did not work with "answer.push(item.variables.line_manager.sys_id);" please try again with "answer.push(item.variables.line_manager);"


View solution in original post

25 REPLIES 25

I am sorry, I am not really knowledgeable at scripting. Do you mean like this?



find_real_file.png



I tried with that, and current.comments = current.variable.line_manager and current.comments = id1 and it did not work,



And yes, the user does have an email address and I get no error when I test it, the workflow goes with no problem to the next activity, the only thing is that it does not really create the approval task for the Line manager that was entered in there.


Hello Yonathan,



What is the actual script you have on "Additional approver Script" in the Approval User activity? I noticed in a previous response you showed something like "current.comments = line_manager", at this point the system is expecting a user "sys_id" and not an assignement. If you still have that, remove it then try again.


Hi David,



I have tried several, these are the ones;



  1. var id1 = current.variables.line_manager;  
  2. answer = [];  
  3. answer.push(id1);


Also,



answer = [];


answer.push(current.variables.line_manager.sys_id);



And:



answer = [];


answer.push(current.variables.line_manager);


When you create a ticket with that workflow, what do you see when you click on the "Show Workflow" link? Does it show in red like it failed? can you post a sample picture?


It is actually skipping the task like if it does not detect the user. It is going directly to the next activity which is another Approval. See images below:



find_real_file.pngfind_real_file.pngfind_real_file.png