Need help for custom variable validation in Catalog client script Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 08:25 PM
I have below requirement.
there is variable name Estimated Cost
Type : it should be upto 2 decimal places or numeric and need to show in SAR currency.
written below code for decimal and numeric checking but how to add currency in Variable??
var decimalRegex = /^\d*(\.\d{1,2})?$/;
g_form.hideFieldMsg('estimated_cost', true);
if (!decimalRegex.test(g_form.getValue('estimated_cost'))) {
g_form.showFieldMsg('estimated_cost', 'Estimated cost must be a numeric or decimal value.', 'error');
}
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 09:08 PM - edited 09-05-2023 09:08 PM
Hi @sony8
you could extend the regular expression to:
var decimalRegex = /^\d*(\.\d{1,2})? (SAR|SR)$/;
You can test this at https://regex101.com/r/kyz4N5/1
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 09:28 PM
@Maik Skoddow when i add above Regex it was showing error for every value i enter in Estimated Cost Variable.
Is there any other way??/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 10:00 PM
Hi Sony,
Can you try this :
^\d+(?:\.\d{1,2})?\s*SAR$
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 12:21 AM
@Vishal Birajdar same field message error is coming