- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 06:33 AM - edited 09-11-2024 06:37 AM
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.
The conditions are out of box activity.result = 'yes' and activity.result = 'no'.
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 06:49 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 06:49 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 06:54 AM
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.