Scripting workflow approval

David Christian
Kilo Guru

I'm trying to script an approval in a workflow on the request item table.   Because the approving person changes based on another variable on the request we are simply using a variable.   I've tried every way I could find in the wiki and the community, but every time the workflow hits this approval it just "skipped" and goes on to the next workflow step.   Any help is greatly appreciated.   Here is my script:

var answer = [];

var approver = new GlideRecord("sys_user");

approver.addQuery("user_name", current.variable_pool.who_approves);

approver.query();

while(approver.next()){

  answer.push(approver);

}

1 ACCEPTED SOLUTION

  1. gs.log('David : Workflow variable print: ' + current.variable_pool.who_approves + ' ' + current.variable_pool.who_approves.getDisplayValue());  
  2. var answer = [];  
  3. var approver = new GlideRecord("sys_user");  
  4. // approver.addQuery("user_name", current.variable_pool.who_approves); // It will return the sys id of the record variable referencing to  
  5. approver.addQuery('sys_id',current.variable_pool.who_approves); // try this line or very next line to it.  
  6. approver.addQuery('user_name',current.variable_pool.who_approves.getDisplayValue();  
  7. approver.query();  
  8. while(approver.next()){  
  9.   gs.log('David : Approver name is: ' + approver.user_name); // Always try to write down log statements to check the logic.  
  10.   answer.push(approver.sys_id);//corrected the last line as well.  
  11. }  

View solution in original post

7 REPLIES 7

  1. gs.log('David : Workflow variable print: ' + current.variable_pool.who_approves + ' ' + current.variable_pool.who_approves.getDisplayValue());  
  2. var answer = [];  
  3. var approver = new GlideRecord("sys_user");  
  4. // approver.addQuery("user_name", current.variable_pool.who_approves); // It will return the sys id of the record variable referencing to  
  5. approver.addQuery('sys_id',current.variable_pool.who_approves); // try this line or very next line to it.  
  6. approver.addQuery('user_name',current.variable_pool.who_approves.getDisplayValue();  
  7. approver.query();  
  8. while(approver.next()){  
  9.   gs.log('David : Approver name is: ' + approver.user_name); // Always try to write down log statements to check the logic.  
  10.   answer.push(approver.sys_id);//corrected the last line as well.  
  11. }  

I needed the .getDisplayValue().   It works now.   Thanks for the input.   You are correct about the gs.log.   Thanks again!


Hello,



So would just using this script generate an approval? I would not have to use the Approval - user activity?



Thanks


Ira