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

gemini17
Kilo Guru

Hi Alex:



Looks like you don't need the double quotes surrounding your variable.   Remove it and also only one = sign, not ==. Try these two changes. Hopefully, it should work.


Cheers.


Danny


P.S: Mark the answer as 'Helpful' and 'Correct' if it works.


Deepak Ingale1
Mega Sage

answer = ifScript();



  function ifScript() {


  if (current.variables.item == "BPCS/ERPLx") { // make sure "BPCS/ERPLx" is the value of the variable.


  return 'yes';


  } else


  return 'no';


  }



The script I have for Approval - User



answer = [];


//answer.push(current.variables.manager); // this will be true only if you have an variable with name manager which stores the value of manager of requester


answer.push(current.request.requested_for.manager); // dot walk to manager of requested_for



Hi Alexandru,



Please check the above suggested code.


I have commented out line no 13. If you have variable with name manager which points to the requested for manager, then you can remove the comments and put it on line 14


Hey Deepak,



Thank you for your fast reply.



I tried your suggestion but unfortunately it didn't work. The workflow ignores the IF and the Approval again



Thanks,



Alex


Can you please cross check your variable name once is it "item" correct ?



And also let me know what is the type of "item" variable.