How to Create Multi Select Lookup in Microsoft Dynamics AX
Do you need a lookup that allows you to select multiple items in Microsoft Dynamics AX? Do you need to store the multiple values in the database? Check out the following example using multi select lookup that allows you to select multiple main accounts in AX.
Use the following steps to create Multi Select Lookup in Dynamics AX:
1. Create an AOT query for the lookup.
2. Create the control on the form, set the auto declaration property to yes
3. In the Modified method of the control:
public boolean modified()
{
boolean ret;
ret = super();
ttsBegin;
SalesParameters.SSI_MainAccountId = SSI_MultisitePostingSales_Invoice_SSI_MainAccountId.text();
SalesParameters.update();
ttsCommit;
return ret;
}
4. In the Class Declaration of the form:
SysLookupMultiSelectCtrl msCtrl;
5. In the Init method of the form:
msCtrl = SysLookupMultiSelectCtrl::construct(element, SSI_MultisitePostingSales_Invoice_SSI_MainAccountId,
queryStr(SSI_MainAccount));
6. On the form datasource Execute query method:
public void executeQuery()
{
super();
this.SSI_updateMainAccountCtrl();
}
7. On the form datasource create a new method to update the ctrl on load of the form:
public void SSI_updateMainAccountCtrl()
{
container mainAccounts;
//Set the control value
SSI_MultisitePostingSales_Invoice_SSI_MainAccountId.text(SalesParameters.SSI_MainAccountId);
//Mark the appropriate checkbox in the drop down
mainAccounts = conNull();
mainAccounts = this.SSI_createContainers();
if (mainAccounts != conNull())
{
// Set controls for existing records
msCtrl.set(mainAccounts);
}
else
{
msCtrl.set(conNull());
}
}
8. On the form datasource create a new method to hold the values that should be checked on the load of the form:
public container SSI_createContainers()
{
List list = new List(Types::String);
ListIterator i;
container RecIds, Names;
RecId id;
//Create Container for the RecIds, Names
list = Global::strSplit(SalesParameters.SSI_MainAccountId,";");
i = new ListIterator(list);
while(i.more())
{
id = MainAccount::findByMainAccountId(i.value()).RecId;
RecIds += id;
Names += i.value();
i.next();
}
return [RecIds, Names];
}
Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.
Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.