web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

how will get exchange rate for sales order line in ax 2012 r3

(0) ShareShare
ReportReport
Posted on by 30

hi all,

i write below code for testing purpose to get exchange rate for sales order line

Gl - setup

sss1.jpg

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

    CurrencyCode fromCurrency  = 'USD';
    CurrencyCode toCurrency    = Ledger::find(Ledger::current()).AccountingCurrency ;     
    TransDate    transDate     = mkDate(7,8,2020);//this.TransDate;

    while select exchangeRateCurrencyPair
    where exchangeRateCurrencyPair.ExchangeRateType == Ledger::find(Ledger::current()).DefaultExchangeRateType
    &&  exchangeRateCurrencyPair.FromCurrencyCode == fromCurrency
    &&  exchangeRateCurrencyPair.ToCurrencyCode   == toCurrency
    {
        exchRate = exchangeRate::findByDate(exchangeRateCurrencyPair.RecId,transDate).ExchangeRate;
        info(strFmt("%1",exchRate/100));
    }

    return exchRate/100;

}

i debugged the above code

form Currency- USD

to Currency =  JPY

transdate =   mkdate();

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

***here i am getting ReciD = 0, if i am not wrong , it should be return Standard

please help me

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: how will get exchange rate for sales order line in ax 2012 r3

    You should use the ExchRateHelper class instead of manually selecting from the table. Check cross references for that class to find examples on how it's used in standard processes. 

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at
    RE: how will get exchange rate for sales order line in ax 2012 r3

    Hi @rp@n,

    In addition, there is the ready-made snippet for getting exchange rate gist.github.com/.../6e1d106b6f12b8cd64350505bafa8bc9 (you can remove usage of exchangeRateTypeRecId parameter)

  • @rp@n Profile Picture
    30 on at
    RE: how will get exchange rate for sales order line in ax 2012 r3

    Hi Sergei,

    Sales order no = 440-000008

    Status = Invoiced

    Invoice date = 07/09/2020

    Currency = USD

    here, i need to get exchange rate based on the date , which is define in exchange rate master for USD to JPY

    here i need to display exchange rate in FX-Rate column in JPY

    i saw the class 

    exchangeRateHelper 

    Report template

    pastedimage1596525371435v1.jpeg

    CODE

        ExchangeRateHelper exchangeRateHelper;
        ;
     
        exchangeRateHelper = ExchangeRateHelper::construct();
        exchangeRateHelper.parmLedgerRecId(Ledger::current());
        exchangeRateHelper.parmFromCurrency(fromCurrency);  // USD
        exchangeRateHelper.parmToCurrency(toCurrency); // JPY
        exchangeRateHelper.parmExchangeDate(exchangeDate); //  NEED TO PASS HERE INVOICE DATE FROM CUST INVOICE TRANS
        exchangeRateHelper.parmExchangeRateTypeRecId(exchangeRateTypeRecId); // IS THIS REQUIRED ??
     
        return ExchangeRateHelper::displayStoredExchangeRate_Static(exchangeRateHelper.getExchangeRate1(),
               ExchangeRateCurrencyPair::getExchangeRateDisplayFactor(fromCurrency, toCurrency, /*exchangeRateTypeRecId,*/ true));
               
               

    Please let me know is t correct?

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: how will get exchange rate for sales order line in ax 2012 r3

    Please let us know if your code works correct. Thanks!

  • @rp@n Profile Picture
    30 on at
    RE: how will get exchange rate for sales order line in ax 2012 r3

    Hi Nikoloas,

    i write job for testing purpose and hard cored the values. because i am working first on ths.

    my code

    public real  SR_CEH_Example1(Args _args)
    
    {
        ExchangeRateHelper      exchangeRateHelper;
        CurrencyCode            fromCurrency,toCurrency;
        Recid                   exchangeRateTypeRecId;
        ;
        fromCurrency = 'JPY';
        toCurrency   = 'USD';
        exchangeRateTypeRecId = 5637565880;  // REC ID form CustInvoiceTrans for salesid = 440-000008
    
        exchangeRateHelper = ExchangeRateHelper::construct();
        exchangeRateHelper.parmLedgerRecId(Ledger::current());
        exchangeRateHelper.parmFromCurrency(fromCurrency);  // USD
        exchangeRateHelper.parmToCurrency(toCurrency); // JPY
        exchangeRateHelper.parmExchangeDate(mkDate(07,09,2020)); // invoice date from Cust Invoice trans for sales id 440-000008
        exchangeRateHelper.parmExchangeRateTypeRecId(exchangeRateTypeRecId); // IS THIS REQUIRED ??
    
        return ExchangeRateHelper::displayStoredExchangeRate_Static(exchangeRateHelper.getExchangeRate1(),
               ExchangeRateCurrencyPair::getExchangeRateDisplayFactor(fromCurrency, toCurrency,exchangeRateTypeRecId , true));
    
    }
    
    

    i got below error

    1273.error.jpg

    i think, it should return the below rate

    EXCR.jpg

    is this error is coming because of no date range? So, it's not able to found the rate based on the date in the Currency rate master

    is it rite?

    please give me more shed on this.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: how will get exchange rate for sales order line in ax 2012 r3

    You need to provide a RecId of a record In ExhangeRateType, if you want to pass ExchangeRateTypeRecId.

    And no, it's not needed at all. Did you already use cross references to learn how ExchRateHelper class is used in the standard system? If not, please do - you will be surprised how much you will learn by observing the standard functionalities.

    Also you will find out that you can call ExchangeRateHelper in a much simpler way than what you did. For example:

    ExchangeRateHelper::exchRate([CurrencyCode], [TransDate]).

  • @rp@n Profile Picture
    30 on at
    RE: how will get exchange rate for sales order line in ax 2012 r3

    Nikoloas,

    as suggested, i have search for the method, it's not exist in Exchange rate helper class

    ExchangeRateHelper::exchRate([CurrencyCode], [TransDate]).

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at
    RE: how will get exchange rate for sales order line in ax 2012 r3

    Hi @rp@n,

    Try to not use exchangeRateTypeRecId in your example, it's not needed and default type will be used from Legal entity or initialize it with default value in your code.

    exchangeRateTypeRecId = Ledger::find(Ledger::current()).DefaultExchangeRateType;

  • @rp@n Profile Picture
    30 on at
    RE: how will get exchange rate for sales order line in ax 2012 r3

    ExchangeRateHelper      exchangeRateHelper;
        CurrencyCode            fromCurrency,toCurrency;
        Recid                   exchangeRateTypeRecId;
        ;
        fromCurrency = 'JPY';
        toCurrency   = 'USD';
        //exchangeRateTypeRecId = 5637144576;
    
        exchangeRateHelper = ExchangeRateHelper::construct();
        exchangeRateHelper.parmLedgerRecId(Ledger::current());
        exchangeRateHelper.parmFromCurrency(fromCurrency);  // USD
        exchangeRateHelper.parmToCurrency(toCurrency); // JPY
        exchangeRateHelper.parmExchangeDate(mkDate(07,09,2020)); // invoice date from Cust Invoice trans for sales id 440-000008
        //exchangeRateHelper.parmExchangeRateTypeRecId(exchangeRateTypeRecId); // IS THIS REQUIRED ??
    
        return ExchangeRateHelper::displayStoredExchangeRate_Static(exchangeRateHelper.getExchangeRate1(),
               ExchangeRateCurrencyPair::getExchangeRateDisplayFactor(fromCurrency, toCurrency,/*exchangeRateTypeRecId ,*/ true));
    
        

    Sergei, if i not use then, i will get error

    2500.q1.jpg

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at
    RE: how will get exchange rate for sales order line in ax 2012 r3

    Hi @rp@n,

    Try to check if the value returned by exchangeRateHelper.getExchangeRate1() is enough for you. The rest of code is related to display factor and maybe you don't need it.

    return exchangeRateHelper.getExchangeRate1();

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,100

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 890 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 633 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans