Skip to main content

QueryBuildDataSource Syntax

 

Let's suppose we have following tables.

- Leave Assignment table - (Base Table) - Namely Parent for demo purpose

- HcmEmployment table - Namely Child 1 for demo purpose

- Leave Plan table - Namely Child 1 for demo purpose


We want to link base table with both hcm employment (child1) and leave plan table (child2)  using query build data source. Below is the code used for performing this operation.


public QueryRun fetchMultipleTableQueryDemo()
{
QueryBuildDataSource hcmEmploymentds;
QueryBuildDataSource qbds;
Query query = new Query();

// Adding parent as a datasource
QueryBuildDataSource qbs = query.addDataSource(tableNum(Parent));


// Adding child 1 as a datasource
hcmEmploymentds= qbs.addDataSource(tableNum(Child1));
hcmEmploymentds.joinMode(JoinMode::InnerJoin);
hcmEmploymentds.addLink(fieldNum(Parent, Worker),fieldNum(Child1, Worker));
hcmEmploymentds.fetchMode(QueryFetchMode::One2One);


// Adding child 2 as a datasource
qbds = qbs.addDataSource(tableNum(Child2));
qbds.joinMode(JoinMode::InnerJoin);
qbds.addLink(fieldNum(Parent, LeaveDetail), fieldNum(Child1, RecId));
qbds.fetchmode(QueryFetchMode::One2One);

return new QueryRun(query);
}


QueryRange Expression syntax for DateTime Util:

queryBuildRange2.value(strFmt('((%1.%2 == %3) || ((%1.%2 == %4) && (%1.%5 == %6)))',
 query.dataSourceTable(tableNum(InventTable)).name(), // InventTable %1
 fieldStr(InventTable, ItemType), // ItemType %2
 any2int(ItemType::Service), // %3
 any2int(ItemType::Item), // %4
 fieldStr(InventTable, ItemId), // ItemId %5
 fieldStr(InventItemBarCode, ItemId))); // %6


DateTimeUtil::tosTr  works for datetimeutil expression.





HEY HEY HEY!!! HACK OF THE DAY!!!
if we want to access AOT query or QueryBuildDataSource Table then we can use:

custInvoiceJourDatasource = salesInvoiceHeaderQuery.dataSourceTable(tableNum(CustInvoiceJour));

Comments

Popular posts from this blog

Edit Method on Form

Edit Method D365 for a form Data Source 1. To create an edit method first create a controller class. with following properties  public static edit MainAccountNum LedgerJournalTransLedger(LedgerJournalTrans _ledgerjournal, boolean _set, MainAccountNum _id) { MainAccountNum accountId = _id; MainAccount mainAccount = MainAccount::findByMainAccountId(_id); if(_set) { if(_ledgerjournal.AccountType== LedgerJournalACType::Ledger) { mainAccount = MainAccount::findByMainAccountId(accountId); if(_ledgerjournal.LedgerDimension) { DimensionDefault defaultDim = LedgerDimensionFacade::getDefaultDimensionFromLedgerDimension(_ledgerjournal.LedgerDimension); _ledgerjournal.LedgerDimension = LedgerDimensionDefaultingEngine::getLedgerDimensionFromAccountAndDim(mainAccount.RecId, DimensionHierarchy::getAccountStructure(mainAccount.RecId), defaultDim); } else { _ledgerjournal.LedgerDimension = LedgerDimensionDefaultingEngine::getLedgerDimensionFromAccountAndDim(mainAccount.RecId, DimensionHierarchy::ge...

Lookup and Mandatory fields on Form using Form event Handlers D365

Lookup and Mandatory fields on Form using Form event Handlers D365 [FormControlEventHandler(formControlStr(VendBankAccounts, VendBankAccount_SLD_BankCode), FormControlEventType::Lookup)] public static void VendBankAccount_SLD_BankCode_OnLookup(FormControl sender, FormControlEventArgs e)     {         Query query = new Query();         QueryBuildDataSource queryBuildDataSource;         FormControlCancelableSuperEventArgs event = e as FormControlCancelableSuperEventArgs;         QueryBuildRange queryBuildRange;         SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(SLD_BankCodes), sender);         sysTableLookup.addSelectionField(fieldNum(SLD_BankCodes, BankCodes));         sysTableLookup.addLookupField(fieldNum(SLD_BankCodes, BankCodes));         sysTableLookup.addLookupField(fieldNum(SLD_BankCode...

Field Level Security In Ax 2012

FIELD LEVEL SECURITY IN AX 2012 In this blog we will discuss field level security applied in  Ax 2012. 1. Field level security is added on form level as well in Ax 2012 its bit different then field level security in D365 2. This also requires privileges to be applied on form specific fields only. Step #1 :  Change datasource property of the field which need to be added in security. Step #2 : Now add these 2 fields in form --- > permissions --- > Read Step #3 : Now finally create privilege and add these fields explicitly in it.       HEY HEY HEY !!!! HACK OF THE DAY  Add Fields in Entry point privilege section of form  Explicitly.