- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 07:18 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2018 06:06 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 07:23 AM
Hi Jordan,
Do you want this change immediately or once record is saved that should be fine?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 07:27 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2018 10:25 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2018 06:06 AM
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.