N/currency Module Script Sample

The following script sample demonstrates how to use the features of the N/currency module.

Obtain the Exchange Rate Between the Canadian Dollar and the U.S. Dollar

The following sample shows how to obtain the exchange rate between the Canadian dollar and the U.S. dollar on a specific date.

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

            /**
 * @NApiVersion 2.x
 */

require(['N/currency'], function(currency) {
    function getUSDFromCAD() {
        var canadianAmount = 100;
        var rate = currency.exchangeRate({
            source: 'CAD',
            target: 'USD',
            date: new Date('7/28/2015')
        });

        var usdAmount = canadianAmount * rate;
    }

    getUSDFromCAD();
}); 

          

General Notices