Search code examples
containerslookupaxaptax++dynamics-ax-2012

Create a Non-Database-Driven Lookup


Lots of references for creating lookups out there, but all seem to draw their values from a query.

I want to add a lookup to a field that will add items from a list of values that do not come from a table, query, or any other data source.

Such as from a string: "Bananas, Apples, Oranges" ..or a container ["Bananas", "Apples", "Oranges"]

Assume the string/container is a dynamic object. Drawing from an static enum is not a choice.

Is there a way to create lookups on the fly from something other than a data source?

Example code would be a great help, but I'll take hints as well.


Solution

  • It isn't the most graceful solution, but this does work, and it doesn't override or modify any native AX 2012 objects:

    Copy the sysLookup form from AX2009 (rename it) and import it into AX 2012.     
    We'll call mine myLookupFormCopy.
    I did a find/replace of "sysLookup" in the XPO file to rename it.
    

    Create this class method:

    public static client void lookupList(FormStringControl _formStringControl, List _valueList, str _columnLabel = '')
    {
    Args    args;
    FormRun formRun;
    ;
    
    if (_formStringControl && _valueList && _valueList.typeId() == Types::String)
    {
        args = new Args(formstr(myLookupFormCopy));
        args.parmObject(_valueList);
        args.parm(_columnLabel);
        formRun = classFactory.formRunClass(args);
        _formStringControl.performFormLookup(formRun);
    }
    }
    

    In the lookup method for your string control, use:

    public void lookup()
    {
    List    valueList = new List(Types::String);
    ;
    
    ...build your valueList here...
    
    MyClass::lookupList(this, valueList, "List Title");
    
    super();
    }