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

Virtual Field

    VIRTUAL FIELD MAPPING IN AN ENTITY D365 FinOps 1. Create an unmapped field in an Entity Fields section and apply following properties to an unmapped field.  2. Same goes for Staging table : 3. Write following bunch of code in Entity code ( Press F7 ):  To check this field use import export in D365 or use excel add in to manipulate this unmapped field.     HEY HEY HEY !!!! HACK OF THE DAY !!!        entitytodatasource -------   write function        datasourcetoentity -------- read function

EXCEL Add-in D365 FO

EXCEL add-in USED FOR D365 DATA ENTITY To use excel add-in for D365 data entities for CRUD operations. You can easily follow below mentioned steps: 1. Open Excel from any Desktop or VM and click on Add-ins option under insert tab: 2. Check if you have Microsoft Dynamics Office Add-ins, If not then download it from Microsoft store: 3. If you have above mentioned Add-in click on this and click add server information: 4. In server URL add your environment URL either dev, UAT or PROD and click OK.  for e.g:  (https://xxxxxxxxxxxxxxxxxxx.dynamics.com/)  5. Click on Design button and it will display below mentioned screen: 6. Click on Select entity data source and choose your desired data entity from list on which you need to perform CRUD operations and click on NEXT: 7. Double click on each field present in AVAILABLE FIELD SECTION to get them in SELECTED FIELD SECTION: 8. Click on Refresh Once and you will be able to see data in your entity in Excel: 9. After making changes to...

Deep Links

  DEEP LINKS FOR SALES ORDERS In this blog we will discuss about generating deep links for any form , record or datasource. Deep links are basically termed for generating URL's through code for any specific record in D365. Using Deep links other environments can access D365 records by using this URL generated from it. 1. In below blog I am creating Deep links for sales order header record. 2. To Access these links one should always be added the user in FinOps to access through URL. Step #1 Create and extension class of  URLUtility class  and also add following code snippet to access this class : using Microsoft.Dynamics.AX.Framework.Utilities; using Microsoft.Dynamics.@Client.ServerForm.Contexts; public static str generateRecordUrl(str _menuItemName, MenuItemType _menuItemType, DataSourceName _dataSourceName, Map _indexFieldValuesMap, DataAreaId _dataAreaId = curExt()) {   System.Uri host = SessionContext::Get_Current().Get_RequestUrl();   UrlHelper.UrlGenerator...