How to select multiple selected values (records) from lookups in Dynamics AX

Create a Query named StudentCourse that contains 2 darasources say, Student & Course.
. Here Course field in Student table acts as a foreign key.
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.

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

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s