approvals based on variable (referrence field)

Anubhav Srivas1
Tera Expert

Hi Experts,

 

based on the Divison selected , i.e. a (reference field) from the department table, I want to trigger approvals based on the below selections. I'm not able to achieve it and require your help in creating a workflow that checks the current value of the division ( which is fetching from department table) and trigger approvals accordingly.

 

the conditions are as follows: 

DivisionLEVEL 1 APPROVERLEVEL 2 APPROVER
Australia CommercialLine Manager( of the requester)Approval Group Name: Australia Commercial BCD
Australia RetailLine Manager( of the requester)Approval Group Name: Australia Retail BCD
Corporate Centre and ServicesLine Manager( of the requester)Approval Group Name: Corporate Centre and Services BCD
Group ServicesLine Manager( of the requester)Approval Group Name: Group Services BCD
Group TechnologyLine Manager( of the requester)Approval Group Name: Group Tech BCD
InstitutionalLine Manager( of the requester)Approval Group Name: Institutional BCD
New ZealandLine Manager( of the requester)Approval Group Name: New Zealand BCD
PacificLine Manager( of the requester)Approval Group Name: Pacific BCD
Technology COO DomainsLine Manager( of the requester)Approval Group Name: Technology COO Domains BCD
10 REPLIES 10

@Anubhav Srivas1 

for workflow I already said you can use script in the advanced section of user/group approval activity

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Manmohan K
Tera Sage

Hi @Anubhav Srivas1 

 

You can use code similar to below and return the sys_id of group to be used in group approval (make changes so that field backend names and group names are correct)

 

var division = current.division.getDisplayValue(); // Division value fetched from the Department table
var answer = [];
var approvalGroup = ''; 

// Set the appropriate approval group based on the division
switch (division) {
    case 'Australia Commercial':
        approvalGroup = 'Australia Commercial BCD';
        break;
    case 'Australia Retail':
        approvalGroup = 'Australia Retail BCD';
        break;
    case 'Corporate Centre and Services':
        approvalGroup = 'Corporate Centre and Services BCD';
        break;
    case 'Group Services':
        approvalGroup = 'Group Services BCD';
        break;
    case 'Group Technology':
        approvalGroup = 'Group Tech BCD';
        break;
    case 'Institutional':
        approvalGroup = 'Institutional BCD';
        break;
    case 'New Zealand':
        approvalGroup = 'New Zealand BCD';
        break;
    case 'Pacific':
        approvalGroup = 'Pacific BCD';
        break;
    case 'Technology COO Domains':
        approvalGroup = 'Technology COO Domains BCD';
        break;
    default:
        // No matching division, handle the case if needed
        break;
}

var groupSysID = '';

var groupGR = new GlideRecord('sys_user_group');
groupGR.addQuery('name', approvalGroup);
groupGR.query();

if (groupGR.next()) {
    groupSysID = groupGR.getValue('sys_id');
}

answer.push(groupSysID);

  

Add the script to group approval activity like below:

ManmohanK_0-1686986992267.png

 

Hi,

 

i tried your sript but it is throwing an error.

AnubhavSrivas1_0-1687158854133.png

@Anubhav Srivas1 

 

You have a typo or undeclared variables in the script you entered in Approval - Group actvity

Check your script for errors

Hi Manmohan,

 

can you please help here?

Thanks,

Anubhav