SysLookupMultiSelectCtrl on Forms in Dynamics AX 6.0 [AX 2012, X++]

Friends,

I was going through some of the new objects/classes which have been introduced in AX 6.0 and found this class SysLookupMultiSelectCtrl helpful, which will serve multi selection in the grid lookup control.

I still remember we had to work around in 5.0 to attain this kind of functionlaity of getting the data from multiple datasources in lookups and adding columns accordingly.

Well in 6.0 – It’s very easy to implement using SysLookupMultiSelectCtrl class.

Below are the steps on how to achieve this :

1) Create a new Query by name CustTableLookup in the AOT >> Queries. Add 2 data sources [In the below example : I have added CustTable and CustTrans as datasources and linked these datasources by setting up relations property to Yes in CustTrans datasource]

2) Remove fields which dont want to be queried on or donot want in the lookup columns by setting the dynamic peroperty to No on the fields in the datasource and by deleting unwanted fields to be selected.

Find the screen shot below for reference.

3) Create a new form in the AOT >> Forms and give a meaningful Name – [I have named it as SR_LookupMultiSelectGrid]

Add a simple string control in the design and Name it as CustAccount and set the autodeclaration property to Yes as we are going to use this control in the X++ code within the form. [Refer screen shot below]

Now please write/override the following methods and copy paste the code

In the classDeclaration

public class FormRun extends ObjectRun
{
SysLookupMultiSelectCtrl msCtrl;
}

Override the init() method on the element and instantiate the SysLookupMultiSelectCtrl by passing the element , control in which you want the lookup and the Query to get the lookup data

public void init()
{
super();
msCtrl = SysLookupMultiSelectCtrl::construct(element, CustAccount, querystr(CustTablelookup));
}

Finally override the task() method and copy paste the below logic

public int task(int _taskId)
{
#task
int ret;

ret = super(_taskId);

if (ret && _taskId == #TaskSave)
{
// Call appropriate saving here…
msCtrl.get(); // get the Returned Ids
}

return ret;
}

Thats it. We are done. Now let’s ee how lookup looks like and how to select the mutliple items in the lookup and the selected values are returned in to the String control. Below screen shot for reference, Notice that in the lookup we have got the fields from different tables and data is filtered accordingly and also we have provision of selecting multiple rows in the lookup [check box ] provided and all you need to do is Mark the rows and click on Ok button
href=”https://dynamicsaxgyan.files.wordpress.com/2011/06/multiselect.jpg”>

Finally On clicking the Ok button – all the multi selected values will be set as a text in the string control as shown below.

For more information: Refer tutorial_LookupMultiSelectGrid
Next post will be on >> LookupMultiSelectDialog

Happy Dax 6ng

Sreenath

4 Responses to “SysLookupMultiSelectCtrl on Forms in Dynamics AX 6.0 [AX 2012, X++]”

  1. Yasir Says:

    Here is my reply,

    Yasir,
    First thing there is a small correction. Even MS didnot give proper example inthe tutorial_LookupMultiSelectGrid form and there its a bug in standard.I will update them.

    in the init() method – you have to get the object instantiated.
    msCtrl= SysLookupMultiSelectCtrl::construct(SysLookupMultiSelectCtrl::construct(element, CustAccount, querystr(CustTablelookup));

    To handle your requirement, override the close method
    and add the below code

    public void close()
    {
    super();
    conView(msCtrl.get());
    }

    Good luck,
    Sreenath

    Its a great blog.nice work. i want to know one thing that you have said above that call appropriate savings in task().
    but when i have implemented the same code above i cant be able to get returned ids in a container in the task(). the task() is not called on selecting values from lookup.i want to save the returned ids of records when the user clicks the ok button of the lookup form .so kindly help me in that matter that where i use the get method so that i can get the returned ids of the selected values.

    hoping for your early response

    • Sreenath Reddy Says:

      Yasir,
      First thing there is a small correction. Even MS didnot give proper example inthe tutorial_LookupMultiSelectGrid form and there its a bug in standard.I will update them.

      in the init() method – you have to get the object instantiated.
      msCtrl= SysLookupMultiSelectCtrl::construct(SysLookupMultiSelectCtrl::construct(element, CustAccount, querystr(CustTablelookup));

      To handle your requirement, override the close method
      and add the below code

      public void close()
      {
      super();
      conView(msCtrl.get());
      }

      Good luck,
      Sreenath

  2. Chaitanya Says:

    Thanks for the information sir,

    Is this same can be done in EP?

    if so can you post that too.. Thank you in Advance…

  3. Sri Says:

    Hi Sreenath,

    I followed your blog and created multiselect lookup and i am saving the selected records in table field.

    when i reopen the i am not able to see the selected records.
    (My requirement is to save the selected records in table field.
    2) close the form and reopen the form, the records should be selected )

    please help me on this, it’s an urgent requirement for me.

    thanks in advance.
    Sri…..


Leave a reply to Yasir Cancel reply