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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 09.05.2023, 20:18   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
thwidmer: Extend Map CustVendTrans
Источник: https://thwidmer.wordpress.com/2023/...custvendtrans/
==============

Scenario

New field MyNewField as NoYes on CustTrans and VendTrans

Simple solution

Obejcts

Create method parmMyNewField on CustVendTans, CustTrans and VendTrans using Table code extensions.

Usage

custVendTrans.parmMyNewField(NoYes::Yes) will work fine if the record hast been inserted.

Issue

If custVendTrans has not yet been inserted a call to custVendTrans.parmMyFlag(NoYes::Yes) will result in the errors
Error executing code: CustTrans table does not have method ‘parmMyNewField’.
or
Error executing code: VendTrans table does not have method ‘parmMyNewField’.

Full Solution

Extend the CustVendTransInterface class to properly handle mapped functions irrespective of the record being created or not.

Objects
  • Create class MyCustVendTransInterface following plugin design pattern, decorated with [… ExportInterfaceAttribute]
    • Create sub-class MyCustTransCustVendTrans
      decorated with [… ExportMetadataAttribute(…CustTrans…), … ExportAttribute(…MyCustVendTransInterface…)]
    • Create sub-class MyVendTransCustVendTrans
      decorated with [… ExportMetadataAttribute(…VendTrans…), … ExportAttribute(…MyCustVendTransInterface…)]
[Microsoft.Dynamics.AX.Platform.Extensibility.ExportInterfaceAttribute]public abstract class MyCustVendTransInterface{ CustVendTransInterface custVendTransInterface; private void initializeCustVendTransInterface(CustVendTransInterface _custVendTransInterface) { custVendTransInterface = _custVendTransInterface; } public CustVendTrans parmCustVendTrans() { return custVendTransInterface.parmCustVendTrans(); } protected void new() { } public static MyCustVendTransInterface createInstance(CustVendTransInterface _custVendTransInterface) { SysPluginMetadataCollection metadataCollection = new SysPluginMetadataCollection(); metadataCollection.SetManagedValue(classStr(MyCustVendTransInterface), tableId2Name(_custVendTransInterface.parmCustVendTrans().tableId)); MyCustVendTransInterface instance = SysPluginFactory::Instance(identifierStr(Dynamics.AX.Application), classStr(MyCustVendTransInterface), metadataCollection); instance.initializeCustVendTransInterface(_custVendTransInterface); return instance; } public NoYes parmMyNewField(NoYes _myNewField= NoYes::No) { return _myNewField; }}[System.ComponentModel.Composition.ExportMetadataAttribute(classStr(MyCustVendTransInterface), tableStr(CustTrans)) ,System.ComponentModel.Composition.ExportAttribute('Dynamics.AX.Application.MyCustVendTransInterface')]public class MyCustTransCustVendTrans extends MyCustVendTransInterface{ private CustTrans parmCustTrans() { return this.parmCustVendTrans(); } public NoYes parmMyNewField(NoYes _myNewField = this.parmCustTrans().MyNewField) { CustTrans custTrans = this.parmCustTrans(); custTrans.MyNewField = _myNewField; return custTrans.MyNewField; }}[System.ComponentModel.Composition.ExportMetadataAttribute(classStr(MyCustVendTransInterface), tableStr(VendTrans)) ,System.ComponentModel.Composition.ExportAttribute('Dynamics.AX.Application.MyCustVendTransInterface')]public class MyVendTransCustVendTrans extends MyCustVendTransInterface{ private VendTrans parmVendTrans() { return this.parmCustVendTrans(); } public NoYes parmMyNewField(NoYes _myNewField = this.parmVendTrans().MyNewField) { VendTrans vendTrans = this.parmVendTrans(); vendTrans.MyNewField = _myNewField; return vendTrans.MyNewField; }}
  • Optional: create extenstion class CustVendTransInterface_My_Extension
    to provide simple access to the newly created class MyCustVendTransInterface
[ExtensionOf(classStr(CustVendTransInterface))]final class MyCustVendTransInterfaceCls_Extension{ private MyCustVendTransInterface MyCustVendTransInterface; public MyCustVendTransInterface MyCustVendTransInterface() { if (!MyCustVendTransInterface) { MyCustVendTransInterface = MyCustVendTransInterface::createInstance(this); } return MyCustVendTransInterface; }}Usage

//if extension CustVendTransInterface_My_Extension implementedMyCustVendTransInterface myCustVendTransInterface = CustVendTransInterface::createInstance(custVendTrans).myCustVendTransInterface()//if extension CustVendTransInterface_My_Extension not implementedMyCustVendTransInterface myCustVendTransInterface = MyCustVendTransInterface::createInstance(CustVendTransInterface::createInstance(custVendTrans))//access fieldmyCustVendTransInterface.parmMyNewField(NoYes::Yes);Final notes

Microsoft documents the extension of maps here:
Extend table maps that are used as interfaces
However the example SalesPurchTable they are using has a special attribute class to decorate the methods (SalesPurchTableInterfaceFactoryAttribute. The example here is both more generic and simpler.



Источник: https://thwidmer.wordpress.com/2023/...custvendtrans/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
thwidmer: Electronic reporting by example: Create a new Bank file definition Blog bot DAX Blogs 0 31.01.2020 19:11
d365technext: Map Enumerator VS Map Iterator Blog bot DAX Blogs 0 29.08.2018 20:16
Классы коллекций (инициализация, сериализация): List, Set, Map. petergunn DAX: База знаний и проекты 10 04.06.2018 18:45
fieldnum и map custVendTrans - как получить идентификатор поля таблицы по мапу? mazzy DAX: Программирование 10 18.08.2015 14:26
CRM DE LA CREME! Editing the CRM Site Map made so easy!!!!... Blog bot Dynamics CRM: Blogs 1 14.02.2010 11:46

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

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

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