Condition in client script if price field == 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 10:21 AM
Hi,
In a UI action, i need to check if a price field is > 0,01 Euros before allow user to submit the form.
Here is what the field looks like :
Here is the alert :
What is the best way to compare price field ?
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 11:24 AM
Hi @Nico12 ,
You should obtain the floating point value using the javascript function parseFloat like this and then compare it
var rate = parseFloat(current.base_rate);
Please refer to this doc as well: https://docs.servicenow.com/en-US/bundle/utah-platform-administration/page/administer/currency/conce...
If my answer has helped with your question, please mark it as correct and accepted solution
Thanks!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 12:39 PM
Hi,
You can compare the value of the price field to 0.01 using a conditional statement in your UI action.
Here's an example of what the script could look like:
var price = parseFloat(g_form.getValue('price_field'));
if (price < 0.01) {
alert('Price must be greater than 0.01 Euros.');
return false; // prevent the form from being submitted
} else {
return true; // allow the form to be submitted
}
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar