Setting currency value via client script

ilkka
Tera Expert

Hi,

I am trying to set currency value to 1 with g_form.setValue("field", "1");

When this client script runs it puts the value 1,00 to the field and after I save the record the value changes to 100.00

I have also tried with GlideAjax but same result. Any ideas?

 

Thanks

.: Ilkka 

1 ACCEPTED SOLUTION

ilkka
Tera Expert

I found the reason for this behaviour and tried it within my own dev instance. It is because this instance has glide.system.locale value of en.FI and it is actually not supported. the locale should be fi.FI 

here is the docs site about system locale

https://docs.servicenow.com/bundle/madrid-platform-administration/page/administer/currency/concept/l...

and here is the list of supported locale values

http://www.oracle.com/technetwork/java/javase/javase7locales-334809.html

Kind of bad situation because the customer I am working on has the same value in production instance as well, and now I am not sure if it is wise to change it. The docs point out that it should not be changed after the instance is in production. 

 

.: Ilkka 

View solution in original post

12 REPLIES 12

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Try using below snippet in the client script.

var currencyis = '1';
alert('Currency is '+currency is);
var parsedcurrencyis = parseInt(currencyis);
alert(parsedcurrencyis);
g_form.setValue('u_currency', parsedcurrencyis); //considering u_currency is the currency field

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

Hi Jaspal,

 

I received an error and obviously, you need to pass a string with g_form.setValue when dealing with currency fields

https://hi.service-now.com/kb_view.do?sysparm_article=KB0691933

 

I tried your code and added toString() into the g_form.setValue but still see the same result. The first value is 1,00 (here separator is a comma) and after save it changes to 100.00 (separator is dot)

 

.: Ilkka 

what input have you mentioned in your client script? is it 1 , and once it set it ,it's appearing as 1,00 ?

can you  tell me what output are you expecting ?

Hi Harshvardhan,

 

I have it like this g_form.setValue("field", "1");

when the client script has run the field has value 1,00 and this would be fine, but after I save the record the value is 100.00 for some reason. so from 1 to 100, not great. Looks like ServiceNow interprets the comma to thousand separator and not as a decimal point

 

.: Ilkka