How to convert currency?

masaya1
Mega Contributor

Can anyone help me to convert currency? We have editable currency fields called "Annual Maintenance Cost" and "Annual Maintenance Cost (Ref). When a user update the "Annual Maintenance Cost" with their currency, I'd like to know the amount in JPY. I configured one business rule below. However, it seems not working. I expected "JPY; 110,000,000" for "USD; 1,000,000"   but the return value was "JPY; 9,090.9091" as shown in the attachment.

# Business Rule

- Timing

Before Update or Insert

- Code

(function executeRule(current, previous /*null when async*/) {

var value = parseFloat(current.u_maintenance.getReferenceValue());

current.u_is_related = current.u_is_related.getReferenceCurrencyCode() + ';' + value;

})(current, previous);

image01.png

image02.png

6 REPLIES 6

SaschaWildgrube
ServiceNow Employee
ServiceNow Employee

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:

https://github.com/saschawildgrube/servicenow-devtools/blob/master/update/sys_script_include_6f29745...

shivashish
Tera Contributor

Please share the correct answer if you have received