Convert one currency to an other in D365fo x++

 Convert one currency to an other in D365fo x++

 Code: 

public real CurrentExchangeRate(CurrencyCode fromCurrency , CurrencyCode toCurrency , TransDate    transDate)
    {

 

        ExchangeRate           exchangeRate;
        ExchangeRateType       ExchangeRateType;
        ExchangeRateCurrencyPair   exchangeRateCurrencyPair;
        real                   exchRate;

 

        if( fromCurrency == toCurrency)
        {
            exchRate = 1;
            return exchRate;
        }
        else
        {
            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;
        }
    }

has context menu

Comments

Popular posts from this blog

D365FO – AX – X++ –Refresh, Reread, Research, and ExecuteQuery

Create Inventory Journal through Code in D365FO X++

SalesLine Reservation in D365fo x++