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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 12.12.2017, 23:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
Table-Group-All pattern filtering in forms
Источник: http://alexvoy.blogspot.com/2017/12/...tering-in.html
==============

When we need to support business scenarios with different types of relations for the same table, it comes to using enums like Table-Group-All. You can find the biggest example, I believe, in PriceDiscTable.

This post is to explain the same approach in a simpler way.

Say, we have a table with two fields defining different possible values for two other relation value fields.



The whole idea is in adding a range with an expression to the form query.



The challenge here is to support correct filtering on the form and combine it with the user filters, after it is open for a particular record. In our case it is a customer that can have a value in Sales commission group (or not) and some matching ZIP code in its primary business address.


void reSelect()
{
str filter;

element.cleanDSQuery();
filter = this.buildViewAllCustomerFilter();
blockCustomerGroupRelation.value(filter);

wblSalesGroupAssignation_DS.executeQuery();
wblSalesGroupAssignation_DS.queryRun().saveUserSetup(false);
wblSalesGroupAssignation_DS.refresh();
}


This method is supposed to be triggered from linkActive() of the datasource. First we clear the original query from possible dynamic links and ranges and create our new range for an expression. You can make it visible to see the final expression for debugging.

private void cleanDSQuery()
{
wblSalesGroupAssignation_DS.query().dataSourceTable(tableNum(wblSalesGroupAssignation)).clearDynalinks();

wblSalesGroupAssignation_DS.query().dataSourceTable(tableNum(wblSalesGroupAssignation)).clearRanges();
blockCustomerGroupRelation = wblSalesGroupAssignation_ds.query().dataSourceTable(tableNum(wblSalesGroupAssignation)).addRange(fieldNum(wblSalesGroupAssignation, wblCustomerTableGroupAll));
blockCustomerGroupRelation.status(RangeStatus::Hidden);
}


Then we create a complex range expression for two fields in two methods.


private str buildViewAllCustomerFilter()
{
str viewAllAgreementFilter;


viewAllAgreementFilter = '((';
viewAllAgreementFilter += element.buildFilterCustomer();
viewAllAgreementFilter += ') && (';
viewAllAgreementFilter += element.buildFilterZipCode();
viewAllAgreementFilter += '))';

return viewAllAgreementFilter;
}


We add Group based condition only if Sales commission value is set up for a given customer.

private str buildFilterCustomer()
{
str filter;
// (
filter = '(';
// (wblCustomerTableGroupAll = Table and wblCustomerGroupRelation = account code)
// OR
// (wblCustomerTableGroupAll = All)
// AND
//

filter += strFmt('((%1.%2==%5) && (%1.%3=="%4")) || (%1.%2==%6)',
wblSalesGroupAssignation_DS.queryRun().query().dataSourceTable(tableNum(wblSalesGroupAssignation)).name(), // 1
fieldStr(wblSalesGroupAssignation, wblCustomerTableGroupAll), // 2
fieldStr(wblSalesGroupAssignation, wblCustomerGroupRelation), // 3
queryValue(custTableFrom.AccountNum), // 4
any2int(TableGroupAll::Table), // 5
any2int(TableGroupAll::All) // 6
);

if(custTableFrom.CommissionGroup)
{
// OR
// (wblCustomerTableGroupAll = Group and wblCustomerGroupRelation = sales commission group)

filter += strFmt(' || ((%1.%2==%5) && (%1.%3=="%4"))',
wblSalesGroupAssignation_DS.queryRun().query().dataSourceTable(tableNum(wblSalesGroupAssignation)).name(), // 1
fieldStr(wblSalesGroupAssignation, wblCustomerTableGroupAll), // 2
fieldStr(wblSalesGroupAssignation, wblCustomerGroupRelation), // 3
queryValue(custTableFrom.CommissionGroup), //4
any2int(TableGroupAll::GroupId) // 5
);
}

filter += ')';
return filter;

}



private str buildFilterZipCode()
{
str filter;
// (
// (wblZipCodeTableGroupAll = GroupId and wblZipCodeGroupRelation = wblBusinessAddressZipCode)
// OR
// (wblZipCodeTableGroupAll = All)

filter = strFmt('(((%1.%2==%5) && (%1.%3=="%4")) || (%1.%2==%6))',
wblSalesGroupAssignation_DS.queryRun().query().dataSourceTable(tableNum(wblSalesGroupAssignation)).name(), // 1
fieldStr(wblSalesGroupAssignation, wblZipCodeTableGroupAll), // 2
fieldStr(wblSalesGroupAssignation, wblZipCodeGroupRelation), // 3
queryValue(custTableFrom.wblBusinessAddressZipCode().wblZipGroupId), // 4
any2int(wblGroupAll::GroupId), // 5
any2int(wblGroupAll::All) // 6
); // 6

return filter;

}


You can easily adapt this code to your own scenario. Just be meticulous with the syntax of the extended range expression.


Источник: http://alexvoy.blogspot.com/2017/12/...tering-in.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
saurav-nav: NAV 2018 - Lots of New Objects! Blog bot NAV: Blogs 0 04.12.2017 10:11
Поставщик Учетная Группа anatol33 NAV: Программирование 9 25.05.2009 22:17
wiki.dynamicsbook: Changes Made in Navision Attain 3.60 Blog bot Dynamics CRM: Blogs 0 02.09.2008 13:23
wiki.dynamicsbook: Changes Made in Navision Attain 3.01B Blog bot Dynamics CRM: Blogs 0 21.08.2008 20:43
wiki.dynamicsbook: Changes Made in Navision Attain 301 Blog bot Dynamics CRM: Blogs 0 19.08.2008 13:44
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

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

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

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