- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2020 03:36 AM
I had requirement on currency conversion, we will enter amount in variable(single line text) and will select currency(reference--fx_currency) so, user will add amount like 1000,200.50 etc and will select currency then amount will convert with USD and populate in new variable.. Below is the screenshot for ref. Please help me on this requirement.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2020 06:02 AM
Sample script below
You can then use GlideAjax and onChange Client Script
Input: currency sys_id, amount
Output: amount in USD
Script:
getConversionValue: function(){
var currencySysId = this.getParameter('sysparm_currencySysId');
var amount = this.getParameter('sysparm_amount');
var selectedToEuroGr = new GlideRecord("fx_rate");
selectedToEuroGr.orderByDesc('sys_created_on');
selectedToEuroGr.addQuery("currency", currencySysId);
selectedToEuroGr.query();
if (selectedToEuroGr.next()) {
var selectedCurrencyToEuro = parseFloat(amount)/parseFloat(selectedToEuroGr.rate);
selectedCurrencyToEuro = selectedCurrencyToEuro.toFixed(3);
var euroToUsdGr= new GlideRecord("fx_rate");
euroToUsdGr.orderByDesc('sys_created_on');
euroToUsdGr.addQuery("currency.code", "USD");
euroToUsdGr.query();
if(euroToUsdGr.next()){
return (parseFloat(euroToUsdGr.rate)*selectedCurrencyToEuro).toFixed(3);
}
return ''; // no conversion found
}
return ''; // no conversion found
},
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
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
01-28-2022 02:47 AM
DevTools is a scoped application with many helpful scripts ready to be re-used.
The built-in currency conversion API object (GlideCurrencyConverter) is a bit tricky to use.
Here you can find a nice wrapper function for currency conversion based on the ServiceNow OOTB functionality:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 06:13 AM
Hi
Thank you for the script. It works for a few currencies. But for few of the currencies, the exchange rates do not get show up. Upon checking, I see, the fx_rate table does not have values for that currency (For eg. NGN, PAB). I also see that "ECB Exchange Rate Load" is active and running daily and updating other currency exchanges.
Why are few currency exchange rates not updated/present?