- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2022 02:38 AM
I have a script include that I am calling from a client script. In the script include I am trying to call Number.toLocaleString() with the locale and option parameters, i.e. Number.toLocaleString("en-GB", {style:"currency", currency:"EUR"}). If i use the function with no parameters (tempNum.toLocaleString()), I get my original number back. However, if I use the locale and option parameters (tempNum.toLocaleString("en-GB", {style:"currency", currency:"EUR"})), I get back null. Does the version of Javascript that Servicenow uses not include Number.toLocaleString with these optional parameters?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2022 05:04 AM
Hi @Michael
As ServiceNow is running on ECMAScript5 so you are getting the null value. To accomplish the requirement the best way as of now is to use .toLocaleString() in the Client Script. As Client Script will use Browser JavaScript version so this is possible on Client-side scripting.
Below is the dummy code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var num = new Number(g_form.getValue('<your_field>')),
sd = g_form.getValue('short_description'),
result = num.toLocaleString("en-US", {
style: "currency",
currency: "USD"
});
g_form.setValue('short_description', sd + ' ## ' + result);
}
From the Script Include you are going to receive error/undefined results.
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2022 05:04 AM
Hi @Michael
As ServiceNow is running on ECMAScript5 so you are getting the null value. To accomplish the requirement the best way as of now is to use .toLocaleString() in the Client Script. As Client Script will use Browser JavaScript version so this is possible on Client-side scripting.
Below is the dummy code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var num = new Number(g_form.getValue('<your_field>')),
sd = g_form.getValue('short_description'),
result = num.toLocaleString("en-US", {
style: "currency",
currency: "USD"
});
g_form.setValue('short_description', sd + ' ## ' + result);
}
From the Script Include you are going to receive error/undefined results.
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2022 05:23 AM
Thank you. This is my exact problem. I think I'll use a UI script and see where that gets me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2022 07:02 AM
Hi @Michael
UI Script can also be a solution but I believe you will ensure that it will not affect performance!
🙂
Thank you so much for marking my answer as correct.
Thanks and regards,
Kartik