- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2019 01:13 AM
Hi,
I have a field which created under single line text and having below client script to only accept numbers plus a period to indicate as price.
How do I round the value with 2 decimal point? And restrict them to only inputting 2 decimal point if user chooses to enter decimal values instead of rounding figures.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var reg = /^[1-9]\d*(\.\d+)?$/;
var ans = g_form.getValue('estimate_price_sgd');
if(!reg.test(ans))
{
alert('Please enter a valid price under SGD currency.');
g_form.clearValue('estimate_price_sgd');
}
}
Thanks in advanced!
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2019 12:59 AM
Hi there,
Because your image shows a Variable, you are talking about a Catalog Client Script? And not Client Script?
Is that correct?
If so:
No need to go for scripting.
Check out the functionality which sinds Madrid is available:
(I see version Madrid in your post)
https://community.servicenow.com/community?id=community_article&sys_id=f5b8a988db057300d82ffb2439961...
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2019 01:33 AM
Hi,
Just a thougth, why using a text filed for a price (maybe you have a reason for it)? It is better to use type Decimal or Currency, this way you will not have to worry about the value validation, e.g. Decimal filed is a number with up to two digits after the decimal points (for example, 12.34), or Currency that can take up to 4 decimal places but you can switch is off in sys_properties to limit just to 2 (it is a default setting). With those field types, you do not have to write additional code to ensure that a valid number was given.
Best regards,
Łukasz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2019 06:11 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2019 12:59 AM
Hi there,
Because your image shows a Variable, you are talking about a Catalog Client Script? And not Client Script?
Is that correct?
If so:
No need to go for scripting.
Check out the functionality which sinds Madrid is available:
(I see version Madrid in your post)
https://community.servicenow.com/community?id=community_article&sys_id=f5b8a988db057300d82ffb2439961...
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2019 01:58 AM
Hi Mark,
Great help!
This is exactly what I am looking for.
Thanks!