Thursday, October 5

AX 2012 - Multi Table Lookup - Join many multi with root table to display a lookup on root table

Lookup table on form datasource field. Here is the code for multi table look.



public void lookup(FormControl _formControl, str _filterStr)
{
    Query                                query           = new Query();
    QueryRun                         QueryRun;
    QueryBuildDataSource    reasoncode;
    QueryBuildDataSource    inventTransWMS;
    SysTableLookup               sysTableLookup;
    ;

    super(_formControl, _filterStr);


    if(TmpInventTransWMS.InventQty < 0)
    {
        reasoncode  = query.addDataSource(tableNum(SL_TransferOrderReasonCode));

//<tag>Repeat<tag>
        inventTransWMS = reasoncode.addDataSource(tableNum(SL_InventTransWMS));
        inventTransWMS.fetchMode(JoinMode::ExistsJoin);

        inventTransWMS.relations(false);
        inventTransWMS.addLink(fieldNum(SL_TransferOrderReasonCode, Code),fieldNum(SL_InventTransWMS, SL_TransferOrderReasonCode));

        inventTransWMS.addRange(fieldNum(SL_InventTransWMS, InventDim)).value(queryValue(TmpInventTransWMS.InventDimId));
        inventTransWMS.addRange(fieldNum(SL_InventTransWMS, InventTransOrigin)).value(queryValue(InventTrans::findRecId(TmpInventTransWMS.InventTrans).InventTransOrigin));
        inventTransWMS.addRange(fieldNum(SL_InventTransWMS, InventTransOrigin)).value(queryValue(InventTrans::findRecId(TmpInventTransWMS.InventTrans).InventTransOrigin));

//you can add more data set by repeat from <tag>repeat</tag> tag.

        sysTableLookup = SysTableLookup::newParameters(tableNum(SL_TransferOrderReasonCode), _formControl);
        sysTableLookup.addLookupfield(fieldNum(SL_TransferOrderReasonCode, code));
        sysTableLookup.addLookupfield(fieldNum(SL_TransferOrderReasonCode, codeDescription));

        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }
}

No comments:

Post a Comment

Popular Posts