I want to convert currency field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 03:46 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2016 04:24 AM
You're going to need an exchange rate - which changes every minute. So you'll either need to specify an average constant rate, or build a web service to get the current exchange rate at the time your code executes.
After you have the exchange rate, it's just simple maths operations.
Total (THB) = Total cost * exchange rate;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2016 01:42 AM
Hi Homkhajorn,
It can be done by writing a UI Script and onChange client script on u_total_cost field.
UI Script:
Name:Anything
Global:Marked True
Script:
GlideForm.prototype.setCurrencyField = function(field, currency, value) {
this.setValue(field+'.display', value);
this.setValue(field+'.currency', currency);
this.setValue(field, currency+';'+value);
}
Client Script:
Type: onChange
Field Name:Total Cost
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var USD=g_form.getValue('u_total_cost');
alert(USD);
var split=USD.split(';');
var SPLIT=split[1];
var COST =parseInt( SPLIT.replace(/,/,''));
//assuming exchange rate is 53.83;
var THB=COST*53.83;
alert(THB);
g_form.setCurrencyField('u_thb_cost',' £', THB);
}
Thanks,
Farukh
PS: Mark Helpful or correct if applicable......!!!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2018 01:20 AM
I know it is an old thred, but still:
There is no need to reinvent the wheel.
Service Now contains an exchange rate table (fx_rate) and a scheduled job that allows you to load the data:
https://docs.servicenow.com/bundle/istanbul-platform-administration/page/administer/currency/concept/currency.html
However, the API does not seem to expose a function to convert from one currency to another.
(This would be easy to provide and very beneficial).
Basically, using said table you convert the original currency to EUR and then from EUR to the target.
(Note that this "double-conversion" might introduce an undue amount of rounding error, depending on your application. I would not use it for a banking application...)
Best
Daniel
If this answer was helpful, I would appreciate if you marked it as such - thanks!
Best
Daniel

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 02:49 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: