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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 14.03.2017, 00:13   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
stoneridgesoftware: Filtering Lookup by Relation in Dynamics 365 for Operations
Источник: https://stoneridgesoftware.com/filte...or-operations/
==============

Last time I showed how to add filtering capabilities to your lookup using the DataInteractorFactory class. This time I intend to show how to extend filtering capabilities to support lookups where there is more than one key field on the target table.

Let’s say we have a table, SSISplitBillingTable, that contains split billing codes for a customer. The primary key for this table would then be the combination of the SplitBillingCode and AccountNum.



This also implies that each customer may have multiple SplitBillingCodes. Because we want to identify a default code for each customer, we will add a foreign key to CustTable.



And a table relation to SSISplitBillingCode to enable the lookup.



When we click the drop-down to select a Split billing code from the CustTable form, we are presented with too many records. The intention is to allow the user to select only Split billing codes that are associated with the current CustTable record. As you can see, the list contains 2 records for the current customer, C0020, and one for customer AA.



It was at this point that I must admit I was a little confused. I had assumed that if I put both fields in the table relation that my list would be properly filtered, but apparently, I would be forced to write a little code to make this work. I knew I didn’t want to add a lookup method to every form that would contain this field because that requires too many modifications and doesn’t do anything to prevent future problems. Instead, I was going to see if I could modify the DataInteractorFactory class. It was here I learned something new.

My approach was to explore the DataInteractorTarget owned by the DataInteractorFactory class. Among other things, this class identifies the field, control, and table relation involved in the lookup. A little investigation led me to the BoundRelation class, and the realization that my scenario was already supported.

Inside the applyFieldDependenciesToQuery method, the BoundRelation class sets up the query used to perform the lookup. It does this by iterating through the collection of dependent fields, adding each field value as a range on the query. The problem was that my dependent fields collection was empty. The reason the collection was empty could be found in the processDictRelation method. This method iterates over the lines in the table relation until it finds the primary key field. Each field it encounters before it is found is added to the dependent field list.

if (thisField == this.fkFieldBinding().fieldId()){ // This is the link that defines the relation from fk field to pk field. pkField = externField;}else if (pkField == 0){ // This field comes before the bound field in the relation definition. To match kernel behavior, add this field as a filter. SysDictField dictField = new SysDictField(primaryKeyTableId, externField); if (dictField != null) { this.dependentFieldsTarget().addEnd(AbsoluteFieldBinding::construct(dictField.name(), dictField.tableName())); this.dependentFieldsSource().addEnd(thisField); }}

This means that to filter our lookup to only those records with a matching AccountNum, we need only reorder the lines in our table relation.



Now when we use the lookup the results are properly filtered.





Источник: https://stoneridgesoftware.com/filte...or-operations/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
stoneridgesoftware: How to Restore Inadvertently Deleted Accounts in Dynamics 365 (CRM modules) Blog bot DAX Blogs 0 12.01.2017 23:15
stoneridgesoftware: Easily Add Addresses Fast Tab in Dynamics 365 for Operations with Logistics Postal Address Grid Blog bot DAX Blogs 0 22.12.2016 21:11
stoneridgesoftware: TFS Code Repository and Dynamics AX Blog bot DAX Blogs 0 16.06.2016 16:11
NAV Team: How to: Set up your Microsoft Dynamics NAV installation for Single Sign-on with Office 365 using Windows PowerShell Blog bot Dynamics CRM: Blogs 0 19.12.2013 15:10
Platform updates overview - 3.70.B - NAV2009 R2 Blog bot Dynamics CRM: Blogs 0 07.02.2011 22:06
Опции темы Поиск в этой теме
Поиск в этой теме:

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

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

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

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