Monday, September 16, 2019

How to get Exchange rate in D365 F&O x++ ?



public display Amount TIDF_ExchangeRate()
{
    ExchangeRate     exchangeRate;
    ExchangeRateType ExchangeRateType;
    ExchangeRateCurrencyPair exchangeRateCurrencyPair;
    real             exchRate;

    CurrencyCode fromCurrency  = this.CurrencyCode;
    CurrencyCode toCurrency    = Ledger::find(Ledger::current()).AccountingCurrency ; //"AED";
    TransDate    transDate     = this.TransDate;


    select firstonly exchangeRateCurrencyPair
    where
        exchangeRateCurrencyPair.ExchangeRateType == Ledger::find(Ledger::current()).DefaultExchangeRateType
    &&  exchangeRateCurrencyPair.FromCurrencyCode == fromCurrency
    &&  exchangeRateCurrencyPair.ToCurrencyCode   == toCurrency;

   // if ( date2str(this.TransDate ,1,1,1) == 5/9/2018);
    exchRate = exchangeRate::findByDate(exchangeRateCurrencyPair.RecId,transDate).ExchangeRate;
    //info(strFmt("%1",exchRate/100));

    return exchRate/100;

}








1 comment:

  1. Great walkthrough on retrieving exchange rates in D365 Finance & Operations using X++. The use of ExchangeRateCurrencyPair and exchangeRate::findByDate() makes it clear how to dynamically fetch conversion rates based on transaction date. Very handy when working with multi-currency ledgers! For frontend developers, exploring tools like html2canvas alternatives can also help when rendering or exporting data visuals from web applications.

    ReplyDelete

What is the primary purpose of using a Solution in Microsoft Power Platform & ALM?

As organizations embrace low-code development with Microsoft Power Platform , it becomes essential to manage and govern apps, flows, and dat...