søndag den 26. oktober 2008

Workflows in forms

In Dynamics Ax 2009 Microsoft have added 2 new properties to the design properties,
  • Workflow Enabled
  • Workflow Datasource

which is used to indicate, that the current form has workflow enabled and which datasource of the form is the workflow datasource. This of course means, that a form only can show workflow for one datasource.

Besides the new properties, there is also a new method canSubmitToWorkflow, which is used to determine if current record has submitted to a workflow.

In some of Microsoft examples the methods is set to return true, but this means it will always submit to a workflow, even if it has already submitted the current record. It also means that you will not be able to track the state of the workflow, since it is always submitting.

What you need to do, it to implement a state field on the datasource to keep track if it has been submitted.

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