If statement always return true when using > or <

Gioo
Tera Expert

Hi everyone,

 

Could you please assist me with the following? I am creating an if statement at the Workflow Editor where I need to check the consumables quantity before assigning that to the user through a script. The script works fine, however, the if statement keeps returning true at all times.


This is my code at the if statement:

 

 

 

//Get consumable sys_id
var consume = current.variables.consumable_model;
//Get consumable quantity
var quantity = current.variables.consumable_quantity;
//Set minimum quantity
var minimumQuantity = '100';
gs.addErrorMessage('Quantity is '+ quantity);

answer = ifScript();
	function ifScript() {
		if (quantity > minimumQuantity) {
			return 'yes';
		} 
		else {
			return 'no';
		}
}

 

 

I have an example where the quantity was 50 and the workflow should have returned no.

Gioo_0-1726061858608.png

 

 

The conditions are out of box activity.result = 'yes' and activity.result = 'no'.

Gioo_0-1726061583707.png

 

Gioo_1-1726061598756.png

 

I have been troubleshooting this issue for a couple days and I don't see to get a way to get it working. Would anyone be able to assist me?

 

Thanks,

Gio

1 ACCEPTED SOLUTION

Hayo Lubbers
Kilo Sage

Hi @Gioo ,

 

Your "minimumQuantity" is set as '100', this means it is interpreted as a string. If you would set it to 100, the script understands it is a number.

I assume your variable is defined as a number/integer, otherwise you have to set it also first as a number (quantity = parseInt(quantity);

 

Hope this helps,

Hayo

 

ps. For new flows, please start working with the Flow Designer

 

View solution in original post

2 REPLIES 2

Hayo Lubbers
Kilo Sage

Hi @Gioo ,

 

Your "minimumQuantity" is set as '100', this means it is interpreted as a string. If you would set it to 100, the script understands it is a number.

I assume your variable is defined as a number/integer, otherwise you have to set it also first as a number (quantity = parseInt(quantity);

 

Hope this helps,

Hayo

 

ps. For new flows, please start working with the Flow Designer

 

Hi @Hayo Lubbers ,

 

Such a small solution that I should have noticed, passing the number without the "" sets the number to integer so parseInt is not needed.

 

Thank you for your assistance.