How to convert other country currency to USD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 04:32 AM
Hello,
i am trying to build one logic on my form, i have 2 fields where we can give currency value
nominal currency&
currency in usd
when i give any value in nominal field value it should automatically convert in USD and should populate in current in USD field
can anyone please suggest me on this how to build the logic
Thank you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 05:11 AM
what do you mean by nominal currency? It should be some currency.
check how you can convert between currencies and then enhance the script for your requirement
fx_rate table stores the conversion value.
Something like this in script to convert USD to GBP
var inc = new GlideRecord('incident');
inc.get('8f54ac5207f9e014540bf2508c1ed034');
gs.info('USD value->' + inc.u_my_currency);
var targetCurrency = 'GBP';
var value = convert(inc.u_my_currency.getCurrencyCode(), inc.u_my_currency, targetCurrency);
gs.info('GBP Value->' + value);
function convert(currencySysId, amount, targetCurrency) {
var currencySysId = currencySysId;
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", targetCurrency);
euroToUsdGr.query();
if (euroToUsdGr.next()) {
return (parseFloat(euroToUsdGr.rate) * selectedCurrencyToEuro).toFixed(2);
}
return ''; // no conversion found
}
return ''; // no conversion found
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 05:58 AM - edited 07-22-2025 05:59 AM
Hi @Ankur Bawiskar ,
I understood the code but what i think Rates are not static, those keep changing everyday with Market so converted value will be just a nearby value(around) , not exact value. - Correct.
Regards,
Nikhil Bajaj
Regards,
Nikhil Bajaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 06:22 AM
that's correct, out of the box fx_rate table is updated I believe on daily basis
We can rely on that.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 07:13 AM
Hi @Ankur Bawiskar ,
Thanks for info.
Regards,
Nikhil Bajaj
Regards,
Nikhil Bajaj