Get the latest exchange rates in Dynamics AX 2012 [Using X++]


Below small snippet will help you to get the latest exchange rates as on today.

I am using x-rates URL to pull the exchange rates for this example. Please check/verify the URL before using it [free source or not].


static void SR_getExchangeRates(Args _args)


    int         curPos, endPos, startPos;

    TextBuffer  tb = new TextBuffer();

    System.Net.WebRequest webRequest;

    System.Net.WebResponse webResponse;

    str page;

    System.IO.StreamReader streamReader;




        webRequest = System.Net.WebRequest::Create("");


        // this will throw an webexception if cannot be reached.

        webResponse = webRequest.GetResponse();

        streamReader = new System.IO.StreamReader(webResponse.GetResponseStream());



        page = streamReader.ReadToEnd();





        curpos   = 1;

        startPos = 1;



        tb.find(‘<a href="/d/INR/USD/graph120.html" class="menu">’, curpos);


        startpos = tb.matchPos();


        tb.find(‘</a>&nbsp;</font></td>’, startpos);

        endpos = tb.matchPos();


        page = tb.subStr(startpos, endpos – startpos);

        info(strFmt("1 USD = %1 INR",strreplace(page,‘<a href="/d/INR/USD/graph120.html" class="menu">’,)));


        // Close the webResonse





        throw error(AifUtil::getClrErrorMessage());



Below is the output:


If anyone is interested in integrating the exchange rates in to the tables ExchangeRate , ExchangeRateType , ExchangeRateCurrencyPair  

[AX 2012] , please drop me an email/message.


Well, to get exchange rates for other currencies you need to modify the URL  as shown below. [Change INR to EUR etc.]



Thank you to


Happy Dax6ng,




2 Responses to “Get the latest exchange rates in Dynamics AX 2012 [Using X++]”

  1. Emre TUFEKCI Says:

    Hi, and thanks for your sharing.
    I’m triyng to integrate my existing class to Ax2012 for reading ExcRates of Turkey.

    I’ve tried the code as a job and it works fine.
    But when i pu it into a class by the same way, it throws an error on the line
    webResponse = webRequest.GetResponse();

    My class is set to be worked on server, my method is static. What is missing?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: