How to Create Multi Select Lookup in Dynamics Ax


Description:-

In this article we will Create Multi select Lookup in Ax using two tables and through AOT (Application Object Tree) Query in Ax. Here is the Example for How to Create Multi Select Lookup in Ax.

Step 1: Create table from DataDictionary>>Table Node to Create table. And Name it “Course”.
Add Fields in the Course table CourseId, CourseType.

Step 2: Now create another table and name it “Student”.
Add Fields in the Student table CourseId, StudentId, StudentName.

Step 3: Now Go to Query Node to Create AOT Query. Give below image for Create AOT Query and Name it “StudentCourse
Use only that field that you want to show on the form or lookup.

Now create a new form named MultiSelectLookup 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 Class Declaration 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()
{
  super();
  // 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++)
    {
      info(conPeek(c,i));
      info(conPeek(v,i));
    }
  }
  return ret;
}

Related Posts

Previous
Next Post »

Thanks for comments.....