How to add Manager Approval in workflow based on custom item variable

alexm3
Kilo Expert

Hello,

We have a workflow named "Software Request" with different assignment groups based on what 'item' is selected in the service catalog form or assignment groups based on requester's location.

We would like to add a "manager approval" when a certain item is selected on the form. To be more specific, when the value "BPCS" is selected in the variable "Item"   the workflow must trigger an approval and send it to the requester's manager. This must apply ONLY for BPCS value. Any other value must continue the normal workflow with not approvals and a task created at the end.

My workflow:

Capture.JPG

The script if have for the "If":

answer = ifScript();

  function ifScript() {

  if (current.variables.item == "BPCS/ERPLx") {

  return 'yes';

  } else

  return 'no';

  }

The script I have for Approval - User

answer = [];

answer.push(current.variables.manager);

The approval is not triggered and the workflow is ignoring the "If" and the "Approval" user and I don't know why.

Any ideas are much appreciated.

Thanks,

Alex

1 ACCEPTED SOLUTION

Hi Alex,



current.variables.item will store the "sys_id" for reference type variable.


You can check the same by generating log statements in your code.



Better way to deal with this kind of scenarios in case of reference and choice list field is to use getDisplayValue() method against variable.



Your modified code should be



  1. function ifScript() {  
  2.   if (current.variables.item.getDisplayValue() == "BPCS/ERPLx") { // BPCS/ERPLx is the value you should see when variable is populated //with corresponding record
  3.   return 'yes';  
  4.   } else  
  5.   return 'no';  
  6.   }  

View solution in original post

8 REPLIES 8

Hi Ravi,


I doublecked and the name of the variable is "item" indeed.



The variable type is Reference.



Thanks,



Alex


Hi Alex,



current.variables.item will store the "sys_id" for reference type variable.


You can check the same by generating log statements in your code.



Better way to deal with this kind of scenarios in case of reference and choice list field is to use getDisplayValue() method against variable.



Your modified code should be



  1. function ifScript() {  
  2.   if (current.variables.item.getDisplayValue() == "BPCS/ERPLx") { // BPCS/ERPLx is the value you should see when variable is populated //with corresponding record
  3.   return 'yes';  
  4.   } else  
  5.   return 'no';  
  6.   }  

Hi Deepak,



It works !



Thank you very much for your help!



Alex


Ravi Prasad1
Tera Guru

Always make sure that for reference field you have to pass sys_id.



If you wish to pass the text then you have to use .getDisplayValue();




Hope it will help you