Get variable Value in workflow

harishdasari
Tera Guru

Hi,

We have variable "Total Cost" in a service catalog form. It is Single Line text variable.

It will have values like 10000 or 20000 or 30000 etc.. like this.

here issue is in IF activity how can i compare the values like greater than or less than, based on that if condition it will route for different approvals.

Here is the script I am using in IF activity in workflow.

This code is not working and by default it is marking IF activity as "NO" and request is getting cancelled.

requirement is IF grand_total value is greater than 10000 it return as "true" , if less than that it should return as "false"

var Grandtotal = current.variables.grand_total.getValue();

 function ifScript() {
     if (Grandtotal > 10000) {
        return 'yes';
     }
     return 'no';
  }

Anyone please help guide on this.

Thank you.

 

1 ACCEPTED SOLUTION

pass the variable in

var Grandtotal = parseInt(current.variables.grand_total.getDisplayValue());

answer = ifScript(Grandtotal);

function ifScript(number) {
if (number > 10000) {
return 'yes';
}
return 'no';
}

 

View solution in original post

10 REPLIES 10

Dubz
Mega Sage

debug the variable to see what value it's returning

gs.log(Grandtotal + ' ' + typeof Grandtotal);

Shashikant Yada
Tera Guru

Please try the below code:

//parseInt(number);

var Grandtotal = parseInt(current.variables.grand_total.getDisplayValue());

function ifScript() {
if (Grandtotal > 10000) {
return 'yes';
}
return 'no';
}

Raju Koyagura
Tera Guru

Technically Single Line Text returns string value so to compare with some number first we need to parse the single line text value from String to Integer something like below

var Grandtotal = parseInt(current.variables.grand_total.getValue());

function ifScript() {

if (Grandtotal > 10000)

{ return 'yes'; }

return 'no'; }

Hi Raju,

 

Thank you for the Response.

 

I have tried your code, it is still not working and IF activity is marking as NO, even though the total cost is 60000

Thank you.