Flow designer script to add approver based on division

Community Alums
Not applicable

Hi Community, 

I'm trying to add approvers in flow designer based on division here is the script but seems to be not working looking for some quick help

var requestorDept = fd_data._1__get_catalog_variables.v_division;
  
  if (requestorDept == 'dept sys_id') {   // 
    return "ApprovesAnyU[approver sys_id]"; // 
  } else if (requestorDept == 'dept sys_id') { // 
    return "ApprovesAnyU[approver sys_id]";  // 
  } else if (requestorDept == 'dept sys_id') { // 
    return "ApprovesAnyU[approver sys_id]"; // 
  } else if (requestorDept == 'dept sys_id') { // 
    return "ApprovesAnyU[approver sys_id]"; // 
  }
1 ACCEPTED SOLUTION

Shruti Khaire
Kilo Sage

Hello @Community Alums,

 

I had somewhat similar requirement where we used location table value to populate assignment group. I'll attach my code snippet below hope it helps.

 

var ritmSysId = fd_data.trigger.request_item.sys_id;
var rec = new GlideRecord('sc_req_item');
rec.get(ritmSysId);

var location = rec.variables.printer_location.primary_location.getDisplayValue();
var assignmentgrp;
gs.log('testing'+ location);

if(location == 'Location_1'){
assignmentgrp="sys_id1";
}else if(location == 'Location_2'){
assignmentgrp="sys_id2";
}return assignmentgrp;

Thank you!

View solution in original post

7 REPLIES 7

Community Alums
Not applicable

the step is skipped and nothing happens after

@Community Alums Can you replace the first line as follows and give it a try.

 

var requestorDept = fd_data._1__get_catalog_variables.v_division+''; //added an empty string to convert the reference to a string for comparision.

Tushar
Kilo Sage
Kilo Sage

Hi @Community Alums 

 

Please try below -

var requestorDept = fd_data._1__get_catalog_variables.v_division;

// Check division and return the appropriate approver role
if (requestorDept == 'dept sys_id 1') {
    return "ApprovesAnyU[approver sys_id 1]";
} else if (requestorDept == 'dept sys_id 2') {
    return "ApprovesAnyU[approver sys_id 2]";
} else if (requestorDept == 'dept sys_id 3') {
    return "ApprovesAnyU[approver sys_id 3]";
} else if (requestorDept == 'dept sys_id 4') {
    return "ApprovesAnyU[approver sys_id 4]";
}

// If no matching division, you might want to handle this case
// with a default approver or some error handling.
return "DefaultApproverRole[default_approver_sys_id]";

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar