Approval based on variable contains

Jake Adams
Tera Contributor

Hi,

 

I have a reference variable that has the reference of 'Business Unit' table.

I want the approval to go based on the Business unit contains, but it's not working for me.

 

In the User approval activity I am using advanced.

 

var answer = [];

if (current.variables.business_unit.indexOf("abc") > -1) {
answer.push(gs.getProperty('approval.one'));
} else {
answer.push(gs.getProperty('approval.two'));
}

 

Kindly assist

12 REPLIES 12

Hi,

 

I have updated the script and used log statements but it's skipping the if statement and only executes the else statement.

 

var answer = [];

if (current.variables.business_unit.getDisplayValue().indexOf("abc") > -1) {
answer.push(gs.getProperty('approval.one'));

gs.log("Approver One: " + answer);
} else {
answer.push(gs.getProperty('approval.two'));

gs.log("Approver Two: " + answer);
}

 

As I mentioned earlier even if the business unit contains abc it is still going to the second approval user, also in the log it's showing the sysid of the second approver

Hi @Jake Adams 

 

can you just check what value it is returning 'current.variables.business_unit.getDisplayValue().indexOf("abc")' by keeping this value in logs.

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

Hi,

 

I have tried it and it's coming like this

 

JakeAdams_0-1678720225736.png

 

var answer = [];

if (current.variables.business_unit.getDisplayValue().indexOf("abc") > -1) {
answer.push(gs.getProperty('approval.one'));

gs.log("Business: " + current.variables.business_unit.getDisplayValue().indexOf("abc"));

//gs.log("Approver One: " + answer);
} else {
answer.push(gs.getProperty('approval.two'));

//gs.log("Approver Two: " + answer);

gs.log("Businesssss: " + current.variables.business_unit.getDisplayValue().indexOf("abc"));
}

@Jake Adams  I think its working fine right . 

 

Business_unit value doesnt contains 'abc'. so it is going to else condition. what is the issue here.

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

No

 

As per the selection the Business unit contains 'abc' so it is going to approver in the else part while it should go for the approver inside the if