Tuesday, November 25, 2025

How to Convert Amounts Between Currencies in D365F&O with X++

This code converts the specified amount from one currency to another using the exchange rates configured in the system, as shown in the images below.

 public Amount getExchangeRateCurrency(Amount _amount)

{

     CurrencyExchangeHelper  currencyExchangeHelper;

     CurrencyCode            toCurrency= SystemParameters::find().SystemCurrencyCode;

  

     TaxAmount               taxAmount;

    currencyExchangeHelper = currencyExchangeHelper::construct();

    currencyExchangeHelper.parmLedgerRecId(Ledger::current()); //gets the current company

    currencyExchangeHelper.parmExchangeRateTypeRecId(Ledger::budgetExchangeRateType()); // gets the budget rate type

 

    return currencyExchangeHelper.calculateCurrencyToCurrency(fromCurrencyCode,toCurrency,_amount, true);  

-------------------------------




No comments:

Post a Comment