Skip to main content

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

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. 
Note: Please check and verify this web URL before using it [free source or not]. 

image 

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; 
try 

webRequest = System.Net.WebRequest::Create("http://www.x-rates.com/d/INR/table.html"); 
// this will throw an webexception if cannot be reached. 
webResponse = webRequest.GetResponse(); 
streamReader = newSystem.IO.StreamReader(webResponse.GetResponseStream()); 
tb.setText(”); 
page = streamReader.ReadToEnd(); 
streamReader.Close(); 
tb.setText(page); 
curpos = 1
startPos = 1
tb.regularExpressions(false); 
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 
webResponse.Close(); 

catch(Exception::CLRError) 

throw error(AifUtil::getClrErrorMessage()); 


Below is the output: 

image 

You can integrating the exchange rates in to the tablesExchangeRate , ExchangeRateType ,ExchangeRateCurrencyPair 

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


image 

Enjoy...........

Comments

Popular posts from this blog

D365 : ENABLE AND DISABLE IN LIST PAGE

 here i have added 4 button in salesQuotationlistpage. now i need to enable/disable button according status. so i have Extensionof  of class SalesQuotationListPageInteraction and modify setButtonEnabled method by Chain of Command //list page button enable and diable in listpage interation class [ExtensionOf(classStr(SalesQuotationListPageInteraction))] final class SQTableinimathod_Extension {     protected void setButtonEnabled()     {                SalesQuotationTable SalesQuotationTable;         CustQuotationJour   CustQuotationJour;         CustQuotationConfirmJour  CustQuotationConfirmJour;               next setButtonEnabled();         SalesQuotationTable SalesQuotationTable1 = this.listPage().activeRecord(queryDataSourceStr(SalesQuotationListPage, SalesQuotationTable));         selec...

An error occurred during report data sets execution D365 For finance and operations

  Hi all, small tip. I faced this issue, when I extend the custom report in D365 for finance and operations. During development on onebox     Solution was simple, restart IIS services Restart Reporting Services. Happy Daxing.

CODE TO PDF IN AX 2012

static void Job1(Args _args) {         PurchPackingSlipController      ssrsController = new SrsReportRunController();         TradeDocumentReportContract     purchPackingSlipContract = new TradeDocumentReportContract();         SRSPrintDestinationSettings     printerSettings;         VendPackingSlipJour             VendPackingSlipJour;         Args                            args;         //select the latest record based on create date         while select VendPackingSlipJour             order by VendPackingSlipJour.createdDateTime DESC             where VendPackingSlipJour.PackingSlipId == 'LJ-01'         ...