Tuesday, July 30, 2013

lookup for SalesId based on customer id in the payment journal ->AR (Ax2012)

public void lookup()
{
    CustTable                           custTable;
    SalesTable                          salesTable;
    Query                               query = new Query();
    SysTableLookup                      sysTableLookup;
    LedgerDimensionAccount              ledgerDim;
    ledgerDim = DimensionStorage::getDynamicAccount(LedgerJournalTrans_AccountNum.valueStr(), LedgerJournalACType::Cust);
    custTable = CustTable::find(DimensionAttributeValueCombination::find(ledgerDim).DisplayValue);
    super();
    // Only user defined dimensions will have a financial tag category
    select firstonly CustAccount from salesTable where salesTable.CustAccount == custTable.AccountNum;
    sysTableLookup = SysTableLookup::newParameters(tableNum(SalesTable), this);
    // Add name field to be shown in the lookup form.
    sysTableLookup.addLookupfield(fieldNum(SalesTable, SalesId));
    sysTableLookup.addLookupfield(fieldNum(SalesTable, CustAccount));
    query = new Query();
    query.addDataSource(tableNum(SalesTable)).addRange(fieldNum(SalesTable, CustAccount)).value(queryValue(custTable.AccountNum));
    sysTableLookup.parmQuery(query);
    // Perform the lookup.
    sysTableLookup.performFormLookup();
}

No comments: