fredag den 12. september 2008

Sort the property sheet

The user options in Axapta and Dynamics AX has a smart function, which enables you to sort the property in the property sheet. When you enable this function, the properties in your property sheets are sorted alphabetical.

The user options is found under Tools -> Options, and the Sort Alphabetical is in the Development tab.

torsdag den 11. september 2008

Sum grid records

Normal way to make totals in a form is to create display methods, preferably on the table, where it will sum all records in the table. But if you only want to sum the records shown in the grids, bearing in mind that the grid can have several filters, it becomes a little trickier.

What you must do is create a new method, that you transfer the datasource of the grid into.


Example:

In this example I want to sum the AmountMST in a CustTrans grid

AmountMST calcSum(FormDataSource _ds)
{
Query query;
QueryRun qr;
QueryBuildDataSource qbds;

CustTrans custTrans;
AmountMST sumAmountMST;
;
query = new Query();
SysQuery::mergeRanges(query, _ds.queryRun().query(), true, true);

qbds = query.dataSourceTable(tablenum(CustTrans));
qbds.addSelectionField(fieldnum(CustTrans, AmountMST), SelectionField::Sum);

qr = new QueryRun(query);

while (qr.next() )
{
custTrans = qr.get(tablenum(CustTrans));
sumAmountMST = custTrans.AmountMST;
}

return sumAmountMST;
}

Traverse grid records

If you want to traverse the records in a grid, the methods you should use are methods getFirst() and getNext() on the form datasource.

Traversing through the active records in a grid can often be useful, either for computing totals or changing the value of fields.

A form datasource has two methods getFirst() and getNext(), which enable you to traverse through the records in a grid. If you only want to traverse the selected methods in the grid, you should use getFirst(true);

Example:

for ( custTrans = CustTrans_DS.getFirst(); custTrans; custTrans = CustTrans_ds.getNext() )
{
totalAmountMST += custTrans.AmountMST;
}