Multiple records selected in a form

In Dynamics AX it is possible to select multiple records in any form, well at least you can if more than one record is visible. This example describes a simple way to handle the selected records before doing something with or to them. In this example we have a clicked-method on a button. If, and only if, the new field “newField” on our table “TestTable” is set on all the selected records, then the super() is run.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
void clicked()
{
    TestTable       tmpRecord;
    boolean         ret = true;
    ;
 
    setprefix("Control on TestTable");
 
    tmpRecord = TestTable_ds.getFirst(true);
 
    if (tmpRecord)
    {
        //Multiple selection
        do
        {
            if(tmpRecord.NewField == "")
            {
                ret = false;
                error(strfmt("Id %1 is missing NewField.", 
                             tmpRecord.Id));
            }
 
            tmpRecord = TestTable_ds.getNext();
 
        } while (tmpRecord);
    }
    else
    {
        //Just one current record selected
        if(TestTable.NewField == "")
        {
            ret = false;
            error(strfmt("Id %1 is missing NewField.", 
                         TestTable.Id));
        }
 
    }
 
    if(ret)
        super();
 
}

This is only a simple example on how to do a validation on the selected records in a form, but the same principle applies for example if you want to delete some of the records based on certain conditions or if you want to update them.

Last 5 posts in Axapta 3.0

Leave a Reply

Your email address will not be published. Required fields are marked *