Thursday, November 7, 2024

Find Current Exchange rate using X++ / Ax

/// <summary>

/// Global class used for generic methods.

/// added by santhosh 

/// </summary>

class LSGlobal

{

    public static real LSexchangeRate(

                                        CurrencyCode fromCurrency,

                                        CurrencyCode toCurrency,

                                        TransDate    transDate = today())

    {

        ExchangeRate                exchangeRate;

        ExchangeRateType            ExchangeRateType;

        ExchangeRateCurrencyPair    exchangeRateCurrencyPair;

        real                        exchRate;

    

        select firstonly exchangeRateCurrencyPair

            where exchangeRateCurrencyPair.ExchangeRateType == Ledger::find(Ledger::current()).DefaultExchangeRateType

            &&  exchangeRateCurrencyPair.FromCurrencyCode   == fromCurrency

            &&  exchangeRateCurrencyPair.ToCurrencyCode     == toCurrency;


        exchRate = exchangeRate::findByDate(exchangeRateCurrencyPair.RecId,transDate).ExchangeRate;

        return exchRate/100;

    }


}