Currency conversion Suitescript using Currency Module

currency.exchangeRate :

Enter an exchange rate for this currency against the base currency of this company, or if you use OneWorld, for this currency against the base currency of the root parent subsidiary. For example, if your company is located in Canada and you are defining the U.S. dollar, and the current exchange rate is 1.02 Canadian dollars to 1.00 U.S. dollar, the Default Exchange Rate for the U.S. dollar is 1.02/1.00, or 1.02. This rate is the basis for rates in the Currency Exchange Rates table that are used in foreign currency transactions. If you use OneWorld, this rate also is the basis for rates in the Consolidated Exchange Rates table that are used in consolidated financials.For more information, see the help topic Setting Currency Exchange Rates.

Sample :

let  exchangeRate = getExchangeRate(lineCurrency, soData.currency,new Date());

    function getExchangeRate(fromCurrency, toCurrency, date) {

        let exchangeRate = 1; // Default to 1 if no conversion is needed

        try {

            // Fetch exchange rate from source to target currency on a specific date

            exchangeRate = currency.exchangeRate({

                source: fromCurrency,

                target: toCurrency,

                date: date

            }) || 1;

            return exchangeRate;

        } catch (e) {

            console.error(‘Error fetching exchange rate:’, e);

        }

        return exchangeRate;

    }

Leave a comment

Your email address will not be published. Required fields are marked *