AX 2012 Table Lookup - systablelookup/sysmultitablelookup

multi table lookup

public void lookup()
{
    Query query = new Query();
    QueryBuildDataSource qbds1;
    QueryBuildDataSource qbds2;

    SysMultiTableLookup sysTableLookUp; 

    qbds1 = query.addDataSource(tableNum(VendTable));
    qbds1.addRange(fieldNum(VendTable,isMill)).value(SysQuery::value(NoYes::Yes));

    qbds2 = qbds1.addDataSource(tableNum(DirPartyTable));
    qbds2.joinMode(JoinMode::InnerJoin);
    qbds2.addLink(fieldNum(VendTable,Party),fieldNum(DirPartyTable,RecId));
      
    sysTableLookup  = SysMultiTableLookup::newParameters(this, query);
        
    sysTableLookUp.addLookupfield(fieldNum(VendTable,AccountNum),true);
    sysTableLookUp.addLookupfield(fieldNum(DirPartyTable,Name),2); 
    
    sysTableLookUp.performFormLookup();
}

single table lookup

private void LookupFactory(FormStringControl _control)
 {
    Query query = new Query();
    QueryBuildDataSource qbds;

    SysTableLookup sysTableLookUp = SysTableLookup::newParameters(tableNum(VendTable), _control, true);

    qbds = query.addDataSource(tableNum(VendTable));
    qbds.addRange(fieldNum(VendTable,isFactory)).value(SysQuery::value(NoYes::Yes));


    sysTableLookUp.addLookupfield(fieldNum(VendTable,AccountNum),true);
    sysTableLookUp.addLookupMethod(tableMethodStr(VendTable,Name));

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

get vendor name

static void lyc_QueryVendName(Args _args)
{
    VendTable vendTable;
    DirPartyTable dirpartyTable;
    Query query = new Query();
    QueryBuildDataSource qbds1;
    QueryBuildDataSource qbds2;
    QueryRun queryRun;
/*
    while select dirpartyTable join vendTable where dirpartyTable.RecId== vendTable.Party && vendTable.AccountNum == "V00325"
    {
        info(strFmt("%1 , %2", vendTable.AccountNum, dirpartyTable.Name));
    }
*/
    qbds1 = query.addDataSource(tableNum(VendTable));
    //qbds1.addRange(fieldNum(VendTable,isMill)).value(SysQuery::value(NoYes::Yes));
    qbds1.addRange(fieldNum(vendTable,AccountNum)).value("V00325");

    qbds2 = qbds1.addDataSource(tableNum(DirPartyTable));
    qbds2.joinMode(JoinMode::InnerJoin);
    qbds2.addLink(fieldNum(VendTable,Party),fieldNum(DirPartyTable,RecId));
    
    queryrun = new QueryRun(query);
    
    while(queryRun.next())
    {
        vendTable = queryRun.get(tableNum(VendTable));
        dirpartyTable = queryRun.get(tableNum(DirPartyTable));
        info(strFmt("%1 , %2", vendTable.AccountNum, dirpartyTable.Name));
    }
}

你可能感兴趣的:(AX 2012 Table Lookup - systablelookup/sysmultitablelookup)