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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 19.07.2021, 20:14   #1  
Blog bot is offline
Blog bot
Участник
 
24,455 / 822 (76) +++++++
Регистрация: 28.10.2006
a33ik: InventSum update event handler
Источник: http://daxonline.org/1720-inventsum-...t-handler.html
==============

Usual update/insert InventSum event handlers to handle simple cases
/// /// Event handlers for InventSum table/// class VKInventSumEventHandler{ /// /// pre insert event handler /// /// PrePost event handler arguments [PreHandlerFor(tableStr(InventSum), tableMethodStr(InventSum, insert))] public static void InventSum_Pre_insert(XppPrePostArgs args) { InventSum inventSum = args.getThis(); InventItemBarcode inventItemBarcode = InventItemBarcode::findItem( inventSum.ItemId, VKUpdateBarcodesService::getProductDimensionsOnly(inventSum.ItemId, inventSum.inventDim()), false, false); inventSum.VKItemBarcode = inventItemBarcode.itemBarCode; } /// /// pre update event handler /// /// PrePost event handler arguments [PreHandlerFor(tableStr(InventSum), tableMethodStr(InventSum, update))] public static void InventSum_Pre_update(XppPrePostArgs args) { InventSum inventSum = args.getThis(); InventItemBarcode inventItemBarcode = InventItemBarcode::findItem( inventSum.ItemId, VKUpdateBarcodesService::getProductDimensionsOnly(inventSum.ItemId, inventSum.inventDim()), false, false); inventSum.VKItemBarcode = inventItemBarcode.itemBarCode; }}Update inventSum advanced case (InventUpdateOnhand.updateInventSum())
/// /// An extension class for InventUpdateOnhand class/// [ExtensionOf(classstr(InventUpdateOnhand))]public final class VKInventUpdateOnhand_Extension{ protected str sqlUpdateInventSumStr() { str sqlSet = ' SET ', sqlFrom = ' FROM INVENTSUMDELTA ', sqlGroupBy = ' GROUP BY ', sqlStr, sqlStrFirst, sqlStrLast, sqlStrInject, newSqlStr; int injectCount = 0; str 256 inventSumName = new SysDictTable(tableNum(InventSum)).name(DbBackend::Sql); str 256 inventSumDeltaName = new SysDictTable(tableNum(InventSumDelta)).name(DbBackend::Sql); str 256 inventSumVKItemBarcodeName = new SysDictField(tableNum(InventSum),fieldNum(InventSum,VKItemBarcode)).name(DbBackend::Sql,0,FieldNameGenerationMode::FieldList); str 256 inventSumDeltaVKItemBarcodeName = new SysDictField(tableNum(InventSumDelta),fieldNum(InventSumDelta,VKItemBarcode)).name(DbBackend::Sql,0,FieldNameGenerationMode::FieldList); // see query structure at header comments of original sqlUpdateInventSumStr method sqlStr = next sqlUpdateInventSumStr(); newSqlStr = sqlStr; // modify SET section to insert our new field update int pos = strScan(newSqlStr, sqlSet, 0, strLen(newSqlStr)); if (pos > 0) { sqlStrInject = strFmt(' %1.%2 = %3.%4, ', inventSumName, inventSumVKItemBarcodeName, inventSumDeltaName, inventSumDeltaVKItemBarcodeName); newSqlStr = this.injectStr(newSqlStr, pos + strLen(sqlSet) - 1, sqlStrInject); injectCount++; } // modify SELECT ... FROM section to select new field from InventSumDelta pos = strScan(newSqlStr, sqlFrom, 0, strLen(newSqlStr)); if (pos > 0) { sqlStrInject = strFmt(', %1.%2 ', inventSumDeltaName, inventSumDeltaVKItemBarcodeName); newSqlStr = this.injectStr(newSqlStr, pos - 1, sqlStrInject); injectCount++; } // modify GROUP BY section to add out field and let it appear in selection pos = strScan(newSqlStr, sqlGroupBy, pos, strLen(newSqlStr)); if (pos > 0) { sqlStrInject = strFmt('%1.%2, ', inventSumDeltaName, inventSumDeltaVKItemBarcodeName); newSqlStr = this.injectStr(newSqlStr, pos + strLen(sqlGroupBy) - 1, sqlStrInject); injectCount++; } if (3 == injectCount) { sqlStr = newSqlStr; } return sqlStr; } public void addInventSumDelta( InventSumDelta _inventSumDelta, InventTrans _inventTrans, InventTable _inventTable) { InventItemBarcode inventItemBarcode = InventItemBarcode::findItem( _inventSumDelta.ItemId, VKUpdateBarcodesService::getProductDimensionsOnly(_inventSumDelta.ItemId, InventDim::find(_inventSumDelta.inventDimId)), false, false); // Calculate/update required field here. InventSumDelta table should also have the same field added to InventSum _inventSumDelta.VKItemBarcode = inventItemBarcode.itemBarCode; next addInventSumDelta(_inventSumDelta, _inventTrans, _inventTable); } protected str injectStr(str _baseStr, int _pos, str _inStr) { str newStr, sqlStrFirst, sqlStrLast; sqlStrFirst = subStr(_baseStr, 0, _pos); sqlStrLast = subStr(_baseStr, _pos+1, strLen(_baseStr)); newStr = sqlStrFirst + _inStr + sqlStrLast; return newStr; }}



Источник: http://daxonline.org/1720-inventsum-...t-handler.html
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 15 Blog bot Dynamics CRM: Blogs 1 10.02.2016 10:26
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 17 Blog bot Dynamics CRM: Blogs 0 10.05.2014 06:30
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 16 Blog bot Dynamics CRM: Blogs 0 23.01.2014 03:15
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 14 Blog bot Dynamics CRM: Blogs 0 12.07.2013 07:13
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 13 Blog bot Dynamics CRM: Blogs 0 27.03.2013 22:12
Опции темы Поиск в этой теме
Поиск в этой теме:

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

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

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

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