Showing posts with label join multi table in lookup in ax 2012. Show all posts
Showing posts with label join multi table in lookup in ax 2012. Show all posts

Tuesday, October 24

AX 2012 - Multi Table lookup - Display Fields from Multiple table in a lookup

Multi Table lookup - Where you can set lookup field from multiple table by joining multiple table and create a multi table lookup using SysMultiTableLookup. 

here is the Demo of the below code:




    Query                   query;
    QueryBuildDataSource    InventTrans;
    QueryBuildDataSource    GroupItem;
    QueryBuildDataSource    EcoRes;

    SysMultiTableLookup sysTableLookup;
    query = new Query();

    InventTrans = query.addDataSource(tableNum(InventTable));
    InventTrans.addRange(fieldNum(InventTable, SL_IncludeInSchemes)).value(queryValue(NoYes::Yes));

    //join the translation table so we can get a description of the UOM
    EcoRes = InventTrans.addDataSource(tableNum(EcoResProductTranslation));
    EcoRes.joinMode(JoinMode::InnerJoin);
    EcoRes.relations(false);
    EcoRes.addLink(fieldNum(InventTable,Product),fieldNum(EcoResProductTranslation,Product));

    //join the translation table so we can get a description of the UOM
    GroupItem = InventTrans.addDataSource(tableNum(InventItemGroupItem));
    GroupItem.joinMode(JoinMode::InnerJoin);
    GroupItem.relations(false);
    GroupItem.addLink(fieldNum(InventTable,ItemId),fieldNum(InventItemGroupItem,ItemId));
    GroupItem.addLink(fieldNum(InventTable,DataAreaId),fieldNum(InventItemGroupItem,ItemDataAreaId));

    //filter by the unit class being passed
    GroupItem.addRange(fieldNum(InventItemGroupItem, ItemGroupId)).value(queryValue(smmParametersTable::find().SL_SchemeReleaseItemGroup));

    //define multiple table lookup query
    sysTableLookup  = SysMultiTableLookup::newParameters(_formControl, query);
    //add which fields will be displayed to the user (symbol + desc.)
    sysTableLookup.addLookupfield(fieldNum(InventTable, ItemId), true);
    sysTableLookup.addLookupfield(fieldNum(EcoResProductTranslation, Name), 2);
    //do not use for multi table
    //sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();

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();
    }
}

Popular Posts