AX Program Object: Trend Analyzer
February 12th, 2009
I’ll be posting various AX program objects and modules all fully commented and free to use how you wish. This program object calculates the min, max, average, sum, and number of records for a selected history and time range. The code shows how to run a BQL query programmatically and demonstrates a history rollup.

Property sheet of Trend Analyzer
The Code:
public void onExecute() throws Exception { String fiftyYearsInMS = "1577846298735"; // Grab the ORD for the selected history String hist = getHistory().toString(); // Grab the start and end dates, note 'encodeToString()' makes it ORD friendly String startDate = getDateRange().getStartTime().encodeToString(); String endDate = getDateRange().getEndTime().encodeToString(); BOrd bqlOrd = BOrd.make(hist + "?period=timeRange;start=" + startDate + ";end=" + endDate + "|bql:historyFunc:HistoryRollup.rollup(select *, baja:RelTime '" + fiftyYearsInMS + "')"); // Run the BQL query BITable result = (BITable) bqlOrd.resolve(Sys.getStation()).get(); ColumnList columns = result.getColumns(); TableCursor c = (TableCursor) result.cursor(); // We should only have one entry in the history since we're querying 50 years c.next(); // Move to 1st (and only) record // Grab the info from the corresponding rows double count = Double.parseDouble(c.get(columns.get(2)).toString()); double min = Double.parseDouble(c.get(columns.get(3)).toString()); double max = Double.parseDouble(c.get(columns.get(4)).toString()); double avg = Double.parseDouble(c.get(columns.get(5)).toString()); double sum = Double.parseDouble(c.get(columns.get(6)).toString()); // Set each value getCount().setValue(count); getMin().setValue(min); getMax().setValue(max); getAverage().setValue(avg); getSum().setValue(sum); }
Tucker its me john i was with you at the vykon booth i downloaded your trendanalyzer added one of my histories and it doesnt seem to update???
JOHN
Hey John – after selecting a history you need to right click on the component and click “Execute”.
hey tucker yeh i had done that and evan ran a trigger to it didnt work. But i reinstalled it and it works fine now thanks.
Hey Tucker any thoughts of bringing obix data into Google Gadgets or yahoo widgets they both support XML and .JS
John
Yep – I actually wrote a Google Gadget a while back that plotted a Line Chart of a live point in AX. I used the “Open Flash Charts” – http://teethgrinder.co.uk/open-flash-chart
It was a custom HX component that was linked to a point and didn’t use obix. It worked in a Google Gadget but it was poorly designed – looking back I should have written some js code to read obix data.
Tucker
They have a newer build looks better
John
Hey Tucker any thought to the use of Air
John
Hey Tucker ever look at aptana ?
John
Hi Tucker,
Nice functionality you brought with the analyzer, and very useful.
I tested with a quite curious result: if I’m right, seems to fail because of the decimal symbol. In Spain we have the comma as decimal separator and in the screenshot we can see the point instead.
Here is the Station Output:
ERROR [10:02:51 28-abr-09 CEST][sys.program] “/Folder/TrendAnalyzer1.onExecute”
java.lang.NumberFormatException: For input string: “0,0″
at sun…
I tried to change Windows Regional configuration, but has no effect on Niagara. I’ll continue finding the way…
Would be possible to adapt program code to solve this question?
Thank you very much!
Hi again,
Finally I found the way to use point instead of comma as decimal separator symbol, but it did not result. Even I tried with a history that has no decimal.
Could you have a look to the Station Output I pasted?
Unfortunately, I have no experience in JavaScript and it is difficult for me to understand, follow nor change the code.
Thank you in advance.
Hi there,
I solved the problem by replacing the ‘,’ with a ‘.’. In my case the log shows “0,0″ but that will not parse in the statement Double.parseDouble(). Now I am parsing “0.0″ and that works fine.
String str = c.get(columns.get(3)).toString();
String str1 = str.replace(‘,’,’.’);
double min = Double.parseDouble(str1);
Good luck