Select multiple selected values (records) from lookups in Dynamics AX


Today i m gonna discuss a concept that will often used in many situations.Somtimes there comes a situation in which we want to select multiple rows from lookups that is, we want to display multiple selected values based on the selection of rows from lookups. So this behaviour can easily be achieved using SysLookMultiSelectCtrl class.
Steps to follow:
Create a Query named StudentCourse that contains 2 darasources say, Student & Course.
The figure below shows the structure of the two tables. Here Course field in Student table acts as a foreign key.
The below figure shows the StudentCourse Query used.
Use only those field that you want to show on the form or lookup.
Now create a new form named MultiSelectLookupCtrl and add a StringEdit control named as TestCtrl in the design node.Set its AutoDeclaration property to “Yes” so that we can access this control from X++ code.
Now override the following methods and write the following code.
In the ClassDeclaration of the form write the below code.
public class FormRun extends ObjectRun
    SysLookupMultiSelectCtrl msCtrl;

Override the init method of the form and place the below code

public void init()
    // TestCtrl – Name of control on which you want a lookup.
   // StudentCourse – Query to get the lookup data
    msCtrl = SysLookupMultiSelectCtrl::construct(element, TestCtrl, querystr(StudentCourse));

That’s it, Now let’s see how the selected rows are returned from the lookup.

On clicking the Ok button all the selected values are returned in the String control. 

To get the values and RecId of the selected rows, simply override the modified method of the TestCtrl and add the below code.

public boolean modified()
    boolean ret;

    container c,v;
    int i;
    ret = super(); 
    if (ret)
        c = msCtrl.get();  // get RecIds of the selected rows
        v = msCtrl.getSelectedFieldValues(); // get actual value of the selected rows

        for (i = 1; i <= conLen(c);i++)

    return ret;

Leave a Reply

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