[X++] SysLookupMultiSelectCtrl with temporary table

Dynamics AX 2012 introduced the nice functionallity called "Multi Select Lookup".
Basically it's a lookup where the user can select more than one value.
An example of standard AX can be found either under \Classes\tutorial_LookupMultiSelectDialog or when taking a look at the Customers (CustTable) on the field "Address books":
Example with CustTable
But what if we want to let the user select multiple values from an temporary table (either tempDB or In Memory)?

Let me show you my solution today.
It was for a lookup on enum values for which i had to use a temporary table.

Table:
  • TableType: InMemory
  • Add 2 Fields "ValueId" (Integer) and "ValueLabel" (String 60)
    Table Properties
The method

... i used to populate the enum values to the table:

public YPSXMLServiceEnumTmp fillTmpEnumTable()
{
    YPSXMLServiceEnumTmp    enumTmp;
    SysDictEnum             dictEnum = new SysDictEnum(enumNum(XmlNodeType));
    int                     idx;

    delete_from enumTmp;

    for (idx = 0;idx < dictEnum.values();idx++)
    {
       enumTmp.clear();
       enumTmp.initValue();
       enumTmp.ValueId = dictEnum.index2Value(idx);
       enumTmp.ValueLabel = dictEnum.index2Label(idx);
       enumTmp.insert();
    }

    return enumTmp;
}
The Query

The Query is used for the lookup later and contains the two fields we want to see in the lookup:
Query

The Form:
  1. Add a StringEdit Control ("AllowedNodeTypes") and set the property AutoDeclaration to Yes.
    StringEdit Control AllowedNodeTypes on Form
  2. classDeclaration
public class FormRun extends ObjectRun
{
    SysFormSplitter_X           splitter;
    SysLookupMultiSelectCtrl    msCtrl;
    QueryRun                    qrEnumValues;
}
  1. init
public void init()
{
    super();
    //Initialize splitter
    splitter = new SysFormSplitter_X(GrpSplitter, GridContainer, element);
	// Populate the data to the temporary table
    YPSXMLServiceEnumTmp.setTmpData(formHelper.fillTmpEnumTable());
    qrEnumValues = new QueryRun(queryStr(YPSXMLServiceEnumTmp));
    qrEnumValues.setCursor(YPSXMLServiceEnumTmp);
    // AllowedNodeTypes = StringEdit Control
    msCtrl = SysLookupMultiSelectCtrl::constructWithQueryRun(element, AllowedNodeTypes, qrEnumValues);
}
The Result:

Result

Next Steps:

The next steps will be to override the modified method and store the selected values.