For any business operating across borders, handling multiple currencies accurately is essential. The N/currency module in SuiteScript 2.x gives developers a reliable way to look up exchange rates and convert amounts between currencies directly within their scripts, ensuring financial calculations stay consistent with NetSuite’s own rate tables.
What the N/currency Module Does
The N/currency module focuses on two closely related jobs: retrieving exchange rates and converting monetary values. Rather than hardcoding rates or maintaining your own conversion logic, you pull the same rates NetSuite uses for transactions, which keeps reports, invoices, and custom calculations aligned with the rest of the system.
Looking Up Exchange Rates
The exchangeRate() method returns the rate between a source and target currency for a given date. You can pass the source currency, the target currency, and an optional effective date to retrieve historical rates. This is especially useful when reconciling older transactions or generating reports that must reflect the rate that applied at the time of a sale.
Converting Amounts
Once you have a rate, converting an amount is straightforward. Multiply the source value by the returned exchange rate to express it in the target currency. Building this into Suitelets, scheduled scripts, or user event scripts lets you display converted totals, populate custom fields, and feed accurate figures into downstream automation without manual intervention.
Code Examples
Example 1 โ Looking up an exchange rate:
require(['N/currency'], function(currency) {
var rate = currency.exchangeRate({
source: 'USD',
target: 'EUR'
});
log.debug('USD to EUR rate', rate);
});
Example 2 โ Converting an amount using a historical rate:
require(['N/currency'], function(currency) {
var rate = currency.exchangeRate({
source: 'GBP',
target: 'USD',
date: new Date('2024-12-31')
});
var amountUSD = 1000 * rate;
log.audit('Converted amount (USD)', amountUSD);
});
Example 3 โ Converting a record amount to the base currency:
require(['N/currency'], function(currency) {
var foreignAmount = 2500; // amount in CAD
var rate = currency.exchangeRate({
source: 'CAD',
target: 'USD'
});
var baseAmount = (foreignAmount * rate).toFixed(2);
log.debug('Base currency amount', baseAmount);
});
Best Practices
Always specify an effective date when accuracy matters, since rates fluctuate daily. Cache frequently used rates within a single execution to reduce repeated lookups and conserve governance units. Round converted values according to the currency’s standard precision, and clearly label which currency a stored amount represents to avoid confusion later.
By leaning on the N/currency module instead of custom rate logic, you build multi-currency NetSuite solutions that are accurate, maintainable, and fully consistent with the platform’s native financial behavior.
Discover more from The NetSuite Pro
Subscribe to get the latest posts sent to your email.
Leave a Reply