Sunday, 3 June 2012

How to use edit methods to mark records

In this post I’ll show how we can use edit methods to mark records on a form and display all the marked records on a click of a button.

To achieve this we’ll :
1. Use a map to store the references of marked records. (PS: we can use other data types, like container , array, lists. We can also use temporary tables. Depends on your comfort level.)
2. Create a new edit method.
3. Add a check box control on Customer Details form (Forms\CustTable).
4. Add a new button to display the information of marked records.

Lets begin:
1. In class declaration of the form declare a map.

2. In the init method of the form , we will initialize this map 

We'll use RecId as the key and AccountNum as the value.Hence the first parameter in map initialization is of type Int64 and second parameter is of type String.

3. Under the methods node of \Forms\CustTable\Data Sources\CustTable, create a new edit method as shown below . 
As we have created this edit method under a form datasource method node we have to provide 3 parameters:
    a) Boolean  - this is used to determine whether the user has entered anything into the control.
    b) CustTable - parameter for the datasource.
    c) Boolean - as the return type of edit method is boolean so the 3rd parameter should also be of type boolean. This holds the boolean value that the user has entered into the control.

Lets understand the logic mentioned in the ablove slide for the edit method.
If the user has amended the value of check box (if(_set)) then:
a)      If user unmark a check box (if(!_mark)) then check if the RecId of unmarked CustTable record exists as a keyvalue in the map. If it exists then remove the corresponding keyvalue (RecId) from the map.
b)      If user mark a check box (else part) then insert the RecId as keyvalue and AccountNum as valuevalue in the map for the marked CustTable record.
Return a boolean: true if the RecId of the current record exists in the map as a keyvalue, false if it does not exists.
Exists method of a map always returns boolean.

4. Now we add a new check box control in the form design and set the properties as shown below. 

5. Now we need a new function to display the information(valuevalue i.e AccountNum) of the records marked by the user. In this function we will iterate through the map(paMarked) using mapEnumerator class and display the information to the user. We can also use mapIterator class for this purpose.

6.Last step is to create a new button on the form, define properties and call the above function(paShowMarked) on its clicked event.

7. Now we are ready to run the process J. We open the customer details form, notice that there is a new check box (Mark) in the overview grid.Now we mark some of the records and then click on show marked button.
An InfoLog will display the AccountNum of all the marked records.

But this is not all. There is lot more to do with the edit methods.
In coming days I'll continue with our journey of edit and display methods .

Until then....
Keep exploring the depths of AX!!!


  1. useful information! thank you very much! :)

  2. very useful information.. Thanks

  3. Hi thanks,
    what if we need to refer to a key that is not all in the same table
    for example we have a grid with

    Custtable in join with Custtrans in outer join with mytable
    where can we put the edit method?
    I ask this because if we put it on the CustTrans , its key (for example RecId) will be repeated for each record in the myTable so it doesn't seem the correct way,
    neither we can put it on the Mytable because it can be empty

  4. Great, easy-to-understand tutorial...will need to check out your other blogs as well!

  5. Tried the same but not working Checkbox is not getting mark.. :(