Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

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

Posted on by 5,901

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

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

    Sure, i will check

    actually yesterday my functional consultant said, to get the value 1.07 exchange rate . So, i set the formula

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

    Hi @rp@n,

    Usually, the exchange rate is stored per 100 (but depends on set up), so in your case, it's not 12.166, but 121.66 (USD->JPY) (12166 \ 100)

    1.07 most likely is JPY -> USD (again it's per 100 JPY)

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

    In CustConfirmJour you can see the actual exchange rate that was used when the confirmation was posted.

    Does your customer want that? If yes, then please use it.

    Your code could return different result for many reasons:

    - Different date is used in your code than what was used for determining CustInvoiceJour.ExchRate

    - You have changed the exchange rates for that date after the confirmation was posted

    - Your code has a bug

    But none of the above are relevant if you actually need the exchange rate of the confirmation. Then there's no need to use time and money struggling with your custom code. That's why its' important to always check if the business requirement can be fulfilled by using the features (or data) that already exists in the standard system.

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

    yes Nikoloas,

    i saw in table CustConfirmJour

    CUSTCONFIRM.jpg

    but it's showing 12.166 exchnage rate

    in my code it's coming 1.07 exchange rate

    please give me more shed on his

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

    By the way, in your code you are selecting CustConfirmJour. You could just use CustConfirmJour.ExchRate without needing to fetch the exchange rate from anywhere else.

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

    Please see this document to learn how to multiply with x : docs.microsoft.com/.../arithmetic-operators

    If you have value "x" in exchangeRate variable, and you would want it to be "100x", following code will do it for you:

    exchangeRate = exchangeRate * 100;

    Is it now clear?

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

    yes, per 1 unit i need the exchange rate. like 1.07 exchange rate in pics i marked

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

    Are you saying that the result that you get is 1/100 of what you would want?

    And you need help in multiplying exchangeRate variable by 100?

    Is this correct?

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

    2134.d1.jpg

    public void  GDJ_ExchangeRates(Args _args)
    {
        SalesTable              salesTable;
        CustConfirmJour         custConfrmJour;
    
        ExchangeRateHelper      exchangeRateHelper;
        CurrencyCode            fromCurrency,toCurrency;
        CustAccount             customerCode;
        TransDate               confirmDate;
        real                    exchangeRate;
        real                    a,b;
    
        ;
        while select SalesTable where SalesTable.SalesId == "SO-0000008"
        {
            customerCode    = salesTable.CustAccount;
            fromCurrency    = custTable::find(customerCode).Currency;  // USD
            toCurrency      = Ledger::accountingCurrency();//"JPY";
    
            select custConfrmJour where custConfrmJour.SalesId == salesTable.SalesId;
            if(custConfrmJour)
            {
                confirmDate = custConfrmJour.ConfirmDate;
                exchangeRate = Currency::exchRate(fromCurrency, confirmDate);
                
                info(strFmt("%1",exchangeRate));
            }
        }
    }

    the above code, return the exchange rate based on Quotation unit = 100 i.e 0.01

    formula = 100/9332.69 = 0.01

    i have required the exchange rate based on quotation unit = 1

    i have required the out put 1.07 exchange rate

    please give me more shed on this

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

    thanks Nikoloas

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans