AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 25.11.2015, 19:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
goshoom: Summarized values in AX form
Источник: http://dev.goshoom.net/en/2015/11/su...es-in-ax-form/
==============

Users sometimes want to see both individual transactions in a grid of a Dynamics AX form, and some summarized values, such as the total amount or the number of lines (often above or below the grid). Iterating through the whole datasource and getting values one by one isn’t efficient, especially if the query returns many rows. A much better solution is taking the query, modifying it to use an aggregation function (such as SUM() or COUNT()) and sending a single, efficient request to database.

My example assumes that I have a form showing customer invoice lines and I want to calculate the total amount of all lines fulfilling current filters (and show it in a separate control).

public void updateTotal() { // Copy the query Query query = new Query(CustInvoiceTrans_ds.queryRun().query()); QueryBuildDataSource qbds = query.dataSourceTable(tableNum(CustInvoiceTrans)); QueryRun qr; CustInvoiceTrans summedTrans; // Sum LineAmountMst qbds.addSelectionField(fieldNum(CustInvoiceTrans, LineAmountMst), SelectionField::Sum); qr = new QueryRun(query); // Run the query qr.next(); // Get the data summedTrans = qr.get(tableNum(CustInvoiceTrans)); // Set the new sum to the control Total.realValue(summedTrans.LineAmountMST); }






The first statement is extremely important, because it defines which query you want to use. I take CustInvoiceTrans_ds.queryRun().query(), because I want to respect filters defined by users. If it wasn’t the case, I would use CustInvoiceTrans_ds.query(). Both scenarios are valid; the choice depends on your functional requirements.

It’s also worth noting that I modified a copy of the query. If I modified the query used by the datasource, I would actually get the summed result in my grid, which wouldn’t make sense.

Then I just have to call the method every time when the datasource query executes.

public void executeQuery() { super(); element.updateTotal(); }








Источник: http://dev.goshoom.net/en/2015/11/su...es-in-ax-form/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Теги
ax2012r3

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
emeadaxsupport: AX Performance Troubleshooting Checklist Part 2 Blog bot DAX Blogs 0 09.09.2014 16:11
goshoom: Merging concurrent changes in AX with TFS Blog bot DAX Blogs 0 02.02.2014 03:23
dynamicsaxtraining: Sales Blog bot DAX Blogs 0 25.04.2012 03:18
dynamicsaxtraining: Purchase Blog bot DAX Blogs 0 11.03.2012 05:25
emeadaxsupport: New Content for Microsoft Dynamics AX 2012 : October 2011 Blog bot DAX Blogs 0 27.10.2011 17:11

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 19:10.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.