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
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()
msCtrl = SysLookupMultiSelectCtrl::construct(element, CustAccount, querystr(CustTablelookup));
Finally override the task() method and copy paste the below logic
public int task(int _taskId)
ret = super(_taskId);
if (ret && _taskId == #TaskSave)
// Call appropriate saving here…
msCtrl.get(); // get the Returned Ids
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
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