No items found.

Building queries with fetchmode property in AX 2012

static void custTableSelect(Args _args)

{

   CustTable   custTable;

   CustGroup   custGroup;

   DlvTerm     dlvTerm;

   #define.custGroup('Net30')

   #define.dlvTerm(LogisticsLocationRoleType::None)

   while select custTable

       join custGroup

           where custGroup.CustGroup == custTable.CustGroup

              && custGroup.PaymTermId == #custGroup

       join dlvTerm

           where dlvTerm.Code == custTable.DlvTerm

              && dlvTerm.TaxLocationRole == #dlvTerm

   {

       info(custTable.AccountNum);

   }

}

We can use standard QueryBuildDataSource classes:

static void custTableQuery(Args _args)

{

   CustTable               custTable;

   QueryBuildDataSource    dsCustTable, dsCustGroup, dsDlvTerm;

   Query                   query = new Query();

   QueryRun                queryRun;

   #define.custGroup('Net30')

   #define.dlvTerm(LogisticsLocationRoleType::None)

   dsCustTable = query.addDataSource(tableNum(CustTable));

   dsCustGroup = dsCustTable.addDataSource(tableNum(CustGroup));

   dsCustGroup.addLink(fieldNum(CustTable, CustGroup), fieldNum(CustGroup, CustGroup));

   dsCustGroup.addRange(fieldNum(CustGroup, PaymTermId)).value(#custGroup);

   dsDlvTerm = dsCustTable.addDataSource(tableNum(dlvTerm));

   dsDlvTerm.addLink(fieldNum(CustTable, DlvTerm), fieldNum(DlvTerm, Code));

   dsDlvTerm.addRange(fieldNum(dlvTerm, TaxLocationRole)).value(queryValue(#dlvTerm));

   queryRun = new queryRun(query);

   while (queryRun.next())

   {

      custTable =  queryRun.get(tableNum(custTable));

      info(custTable.AccountNum);

   }

}

The problem is that above code will not work properly. The built queries will be separated, not joined. To make it work as expected we have to use FetchMode property for QueryBuildDataSource. By default QueryBuildDataSource has property FetchMode == QueryFetchMode::One2Many. We need to set this property to FetchMode == QueryFetchMode::One2One. See below:

static void custTableQuery(Args _args)

{

   dsCustGroup = dsCustTable.addDataSource(tableNum(CustGroup));

   dsCustGroup.addLink(fieldNum(CustTable, CustGroup), fieldNum(CustGroup, CustGroup));

   dsCustGroup.addRange(fieldNum(CustGroup, PaymTermId)).value(#custGroup);

   dsCustGroup.fetchMode(QueryFetchMode::One2One);

   dsDlvTerm = dsCustTable.addDataSource(tableNum(dlvTerm));

   dsDlvTerm.addLink(fieldNum(CustTable, DlvTerm), fieldNum(DlvTerm, Code));

   dsDlvTerm.addRange(fieldNum(dlvTerm, TaxLocationRole)).value(queryValue(#dlvTerm));

   dsCustGroup.fetchMode(QueryFetchMode::One2One);

}

Zobacz inne

Wsparcie i rozwój

Podwykonawstwo Dynamics 365 Finance and Operations dla integratorów i partnerów Microsoft

Czytaj artykuł
Text Link
Wsparcie i rozwój

Kiedy wzmocnić zespół Dynamics 365 Finance and Operations zewnętrznym konsultantem

Czytaj artykuł
Text Link
Wsparcie i rozwój

Skąd wziąć konsultanta Dynamics 365 Finance and Operations do projektu

Czytaj artykuł
Text Link
Wróć do wszystkich

Szukasz partnera Microsoft? Porozmawiajmy o Twoim projekcie

Pracuj z zespołem, który zrealizował wdrożenia i projekty dla dziesiątek firm. Umów rozmowę wstępną i sprawdź:

Jak Dynamics 365 dopasować do procesów Twojej firmy, a nie odwrotnie

Które obszary warto zautomatyzować, żeby odzyskać czas i obniżyć koszty

Jak wygląda wdrożenie z Anegis krok po kroku: od analizy po wsparcie po starcie

Wybierz termin spotkania
Dziękujemy za wiadomość!
Oops! Something went wrong while submitting the form.
Microsoft AI Builder
Microsoft Copilot Studio
No items found.
No items found.
No items found.