Search code examples
axaptadynamics-ax-2012x++

How to make lookup of all fields in a table in ax 2012?


enter image description here

I have a form where the user can select any available table in the AOT in a dropdown/combobox (no. 1 where it says salestable)

Now i want to make a lookup in no.2 of all fields in the table selected in no. 1. I need to get this just based on the table name... I wish for the lookup to contain both the system name of the field and the label of the field. Is this possible? I have tried a good deal of solutions but i haven't been able to get it yet.

Any suggestions would be greatly appreciated.


Solution

  • This is my final solution:

    I made a regular table (TableFieldLookupTmp) containing the fields: tableId, label and field. I insert into this table from dicttable loop.

    If the table already has been added before, i just do the lookup. It works fast.

    Thanks for the help, guys.

    public void lookup()
    

    {

    SysTableLookup SysTableLookup;

    TableFieldLookupTmp TableFieldLookupTmp;
    
    QueryBuildDataSource queryBuildDataSource;
    QueryBuildRange     queryBuildRange;
    Query query         = new Query();
    
    tableName           tableName = 'SalesTable';
    int tmpTableid =    tablename2id(tableName);
    int i;
    
    DictField           dictField;
    DictTable dictTable = new DictTable(tableName2id(tableName)); 
    
    if(!(select TableFieldLookupTmp where TableFieldLookupTmp.TablenumId == tmpTableid).recid)
    {
        ttsBegin;
        if (dictTable)
        {
            for (i=1; i<=dictTable.fieldCnt(); i++)
            {
                dictField = new DictField(dictTable.id(), dictTable.fieldCnt2Id(i));
    
                if(subStr(dictField.name(),0,4) == "DEL_")
                    continue;
                else
                {
                    TableFieldLookupTmp.Label = dictField.label();
                    TableFieldLookupTmp.field = dictField.name();
                    TableFieldLookupTmp.TableNumId = tmpTableid;
                    TableFieldLookupTmp.insert();
                }
            }
        }
        else
        {
            error(strFmt("Table '%1' not found!", tableName));
        }
        ttsCommit;
    
    }
    
    
    sysTableLookup = SysTableLookup::newParameters(tableNum(TableFieldLookupTmp), this);
    
    sysTableLookup.addLookupField(fieldNum(TableFieldLookupTmp, field));
    sysTableLookup.addLookupField(fieldNum(TableFieldLookupTmp, label));
    
    queryBuildDataSource = query.addDataSource(tableNum(TableFieldLookupTmp));
    queryBuildDataSource.addSortField(fieldNum(TableFieldLookupTmp, field), SortOrder::Ascending);
    queryBuildRange = queryBuildDataSource.addRange(fieldNum(TableFieldLookupTmp, TablenumId));
    queryBuildRange.value(int2str(tmpTableid));
    
    //queryBuildRange.value('!DEL_*');
    
    sysTableLookup.parmQuery(query);
    
    sysTableLookup.performFormLookup();
    
    //super();
    

    }