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

Karthik Reddy T
Kilo Sage

Hi Masaya,



Refer the below links may helpful to you.



Currency conversions



Scripting Currency and Price Fields - ServiceNow Wiki



I want to convert currency field


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

Harsh Vardhan
Giga Patron

Hi Masaya,



Please check the thread below. Hope it will help you



Currency Script Calculation Woes


masaya1
Mega Contributor

Hi Karthik and Harshvardhan,



Thank you for your references. They must work for me but I found that my exchange rate was incorrect. After fixing the exchange rate, my code works fine.



On the other hand, do you know how can I get a value with a budget reference rate? When I using "getReferenceValue", it returns a number with a exchange rate. But it is easy for us to control a budget reference rate.



Best Regards,


Masaya Takeda


Yoga
Kilo Contributor

How did u fix the exchange rate?