April 01, 2013

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...........

-Harry

March 30, 2013

How to handle SSRS reports which will take long time

How to handle SSRS reports which will take long time

We know that there are/will be some reports which will take more time to render due to the many rows/transactions. This post will help you to show appropriate warning/error messages to the end user while running the report.

The number of records that are processed by report might be large and the user experience will be affected, because the client will be locked up if printing to the screen. 

In this case, you might want to return a warning message to the user that indicates that time to process the report might be long and confirm that they want to run the report. 

Another case could be where the number of records being processed is very large and a time-out might occur in report processing and clearly, we should not run this report.
In this case, we should not run the report and therefore, should return anSrsReportPreRunState::Error enumeration value with the error message.
In AX 2012, SSRS reports, through SrsReportRunController we can easily let the user know the report will take more time with warnings or error messages through preRunValidate method.

Example : General Journals report

Take the standard example of Print journal from General Ledger >> Reports >> Journal >> Print journal.

Use standard LedgerJournalController class to help you understand preRunValidate method: this validates container before running the report. Override this method to do custom pre-validation for any report. Typical use of this method will be to validate if the time taken to run the report is acceptable.
In this standard example: If the query is going to retrieve more than 1000 rows, a confirmation Box will be displayed to the user as shown below.

To get the confirmation box and for the sake of the demo/understanding: I have hardcoded the rows count to 1001 as shown below. There is a new static method in QueryRun::getQueryRowCount that will get the row Count of the query.

Please note: Remove hardcoded values later. This is hardcoded only for the sake of demo/Walk through
Clearly in the below standard example : warning limit is 1000 and error limit is 100000. 


image

Run this report as shown below...

image


Here comes the confirmation Box: 
If your report is long running, it may time-out. Do you want to continue?

Note: In order to resolve/by pass this confirmation Box, a developer can change the macro #define.warningLimit to greater value

Example : #define.warningLimit(2000);

image

you can increase the row count : to 1000001.

image

Let us run the report One more time as shown below.

image


Here comes the error message: Running the report has been cancelled due to the time it will take to run. Adjust the parameters of the report and retry.
In order to resolve this problem, Increase the ErrorLimit macro value in thepreRunValidate method.
Please note, it is not recommended to increase as it will take more time and your box cannot handle load.


Example : #define.ErrorLimit(150000);
image


Click below for original post...

-Harry