Formatting Currency Field with Decimal Places - OnChange Client Script

Jordan Rose1
Kilo Expert

I have what I feel should be an easy fix (at least in JavaScript outside of ServiceNow).  I have a requirement of displaying a currency field with two decimal places no matter what the value is.  When I edit the field client-side in a form and input a value that is just an integer, I need the value to display '.00' after the integer.  

I am able to do this though onChange by changing ANOTHER field's value using .toFixed(2), but I don't know how to change the newValue (current value) through an onChange client script.  I'm sure this is disabled because of potential looping issues.

How can I get a fixed two decimal format to be added to all user inputted values on the client side for a currency form field?

Thanks

1 ACCEPTED SOLUTION

Jordan Rose1
Kilo Expert

Hi Ankur,

 

Your answer was just a question, so I'm not sure how it could be correct.  I found out a workaround that i'll share with the community.  I ended up using jQuery on the Form Widget to add an onBlur function to all data-type="currency" fields in the form.  I end up doing my currency formatting in that onBlur script and that seems to work properly.

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Jordan,

Do you want this change immediately or once record is saved that should be fine?

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Jordan Rose1
Kilo Expert

Once it's saved, it is displayed properly in the database and on other pages I pull the value into.  I have my currency/decimal settings properly defined for the instance.  It's only on the client side where I need this fix.  In javascript it would just be a function where the field loses focus.  I just don't see a way to modify the value of the same field where the onChange runs against in a client script.

Hi Jordan,

Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Jordan Rose1
Kilo Expert

Hi Ankur,

 

Your answer was just a question, so I'm not sure how it could be correct.  I found out a workaround that i'll share with the community.  I ended up using jQuery on the Form Widget to add an onBlur function to all data-type="currency" fields in the form.  I end up doing my currency formatting in that onBlur script and that seems to work properly.