Thursday, 22 April 2010

AX - MultiSelectionHelper

Today I learned a new class which I think is great.
http://msdn.microsoft.com/en-us/library/cc639186.aspx
The MultiSelectionHelper class provides an interface to work with multiple selected records on a form data source. Say you want to highlight a number of records and run a function against them.
Here is some sample code:
public void initFromArgs(Args _args = this.parmArgs())
{
    MultiSelectionHelper    multiSelectionHelper;
    PurchReqTable           purchReqTable;
    ;

    if (args && args.caller() && args.record())
    {
        multiSelectionHelper = MultiSelectionHelper::createFromCaller(args.caller());

        multiSelectionHelper.createQueryRanges(queryRun.query().dataSourceTable(tablenum(PurchReqTable)), fieldstr(PurchReqTable, PurchReqId));

        switch(args.record().TableId)
        {
            case tablenum(PurchReqTable) :
                purchReqTable= multiSelectionHelper.getFirst();
                while (purchReqTable)
                {
                    info(purchReqTable.PurchReqId);

                    purchReqTable = multiSelectionHelper.getNext();
                }
                break;
        }
    }
}

No comments: