Wednesday, 16 December 2015

Use table method in Lookup x++ AX 2012

Create lookup using table method on Dynamics AX 2012


Many time it is require to show field on lookup x++ in Dynamics AX 2012 which is not directly on the table or table field. In that case table method will be useful in lookup to show relative data. Only problem is it won’t be filtered. 

Here is the code to get data from table method in lookup.

public void lookup()
{
    Query                   qr = new Query();
    QueryBuildDataSource    qbds;
    QueryBuildDataSource    qbdsJoin;
    QueryBuildRange qbr,qbr1;

    QueryRun                qrun;
    SysTableLookup          sysTableLookup = sysTableLookup::newParameters( tableNum(ProjTable), this);
    ;
    qbds= qr.addDataSource( tableNum(ProjTable));
    qbds.joinMode(JoinMode::InnerJoin);
    qbds.relations(true);    
    
    sysTableLookup.addLookupfield( fieldNum(ProjTable, ProjId));
    sysTableLookup.addLookupfield( fieldNum(ProjTable, Name));   
    sysTableLookup.addLookupMethod(tableMethodStr(ProjTable,YourMethod));    
    sysTableLookup.parmQuery(qr);
    sysTableLookup.performFormLookup();

}

Method on ProjTable
public display str 20 YourMethod()


{
 // code 
}


This helped you..!! Then hit the ads on the page..:)