Workflow if condition is not working as expected

surajsukuma
Tera Contributor

In one of Catalog item, I created a single line text variable with Validation Regex as currency.  

surajsukuma_0-1732032955319.png

 

I need if condition if the Variable value >$5000 should go to approval task if no then no approval 

 

I created condition like below screenshot and its not working as expected, approval is going <$5000 as well

 

surajsukuma_1-1732033144263.png

 

Any once can suggest what is wrong with this?

 

Thanks in advance 

 

 

1 ACCEPTED SOLUTION

You should be using a Script with the Advanced box checked, which means you need to delete the Condition so that the script runs without being influenced by the condition.  If it still doesn't work with the latest script I proposed with the temporary log to confirm the value, (which works in a background script using hard-coded values as your test case) try removing the $ as @mahemoodhus suggested, but in your script it would just be:

answer = ifScript();

function ifScript() {
    var amt = parseInt(current.variables.expected_amount.toString().replace('$', '');
    workflow.info('amount is ' + amt);
    if (amt <= 5000) {
        return 'yes';
    }
    return 'no';
}

View solution in original post

9 REPLIES 9

Brad Bowman
Kilo Patron
Kilo Patron

Try this without the condition, and check the Advanced box to use a script instead like this, or whatever logic works with what you're trying to do:

answer = ifScript();

function ifScript() {
    if (current.variables.var_name <= '$5000') {
        return 'no';
    }
    return 'yes';
}

@Brad Bowman  

 

thank you for your reply, 

I tried this script and its didn't work, same issue, I am not sure it field format issue or not 

surajsukuma_0-1732622573556.png

 

You can try to force it to a string - even though this shouldn't be necessary, it can't hurt - then log the value

answer = ifScript();

function ifScript() {
    var amt = current.variables.expected_amount.toString();
    workflow.info('amount is ' + amt);
    if (amt <= '$5000') {
        return 'yes';
    }
    return 'no';
}

Note that the return values are 'yes' and 'no' not capitalized.  What test amounts are you trying, what does the log show (viewable via the Workflow Context related link on the RITM, Log tab) and which values are returned for each?  With this logic, the No path should lead to the Approval activity.

I created condition like below 

and issue, 

If the amount starting above 5, like $6, $650, $75, $850 approval is going

if the amount starting below 5 number like $4, $45, $350 etc approval is not going 

and >$5000 always going to approval which is correct 

surajsukuma_0-1732631358949.png