11.07.2024, 22:18 | #1 |
Участник
|
dynamicsaxinsight: D365: How to write event handler for QueryExecuting event
Источник: https://dynamicsaxinsight.com/2024/0...ecuting-event/
============== Purpose: Demonstrate how can we write an event handler for QueryExecuting form datasource event. Application: Dynamics 365 for Finance and Operations Business requirement: Business requirement is to hide records in a form based on a given condition. Solution: We can use the code below to dynamically add ranges to a form datasource using an event handler for QueryExecuting event. Code internal final class ATLAS_VendTableLookup_Form_EventHandler{ /// /// ATLAS_12220_AddVendGroupToPurchCreateOrder May 23, 24 MK /// /// /// [FormDataSourceEventHandler(formDataSourceStr(VendTableLookup, VendTable), FormDataSourceEventType::QueryExecuting)] public static void VendTable_OnQueryExecuting(FormDataSource sender, FormDataSourceEventArgs e) { FormStringControl ATLAS_PurchTable_VendGroupControl; QueryBuildDataSource qbds_VendTable; QueryBuildRange qbr_VendTable; ATLAS_HcmWorkerSite workerSite; VendGroupId vendGroupId; HcmWorker currentWorker; FormRun callerFormRun; FormRun formRun; formRun = sender.formRun(); callerFormRun = formRun.args().caller(); currentWorker = HcmWorker::find(HcmWorkerLookup::currentWorker()); if (callerFormRun.name() == formStr(PurchCreateOrder)) { ATLAS_PurchTable_VendGroupControl = callerFormRun.control(callerFormRun.controlId(formControlStr(PurchCreateOrder, ATLAS_PurchTable_VendGroup))); if (ATLAS_PurchTable_VendGroupControl) { vendGroupId = ATLAS_PurchTable_VendGroupControl.text(); if (vendGroupId) { qbds_VendTable = sender.query().dataSourceName(tableStr(VendTable)); if (qbds_VendTable) { qbr_VendTable = SysQuery::findOrCreateRange(qbds_VendTable, fieldNum(VendTable, VendGroup)); qbr_VendTable.status(RangeStatus::Hidden); qbr_VendTable.value(queryValue(vendGroupId)); } } } if (SysUserInfo::find(curUserId()).ATLAS_RestrictVendorsBySite) { qbds_VendTable = sender.query().dataSourceName(tableStr(VendTable)); if (qbds_VendTable) { while select workerSite where workerSite.Worker == currentWorker.RecId { qbr_VendTable = qbds_VendTable.addRange(fieldNum(VendTable, InventSiteId)); qbr_VendTable.status(RangeStatus::Hidden); qbr_VendTable.value(SysQuery::value(workerSite.SiteId)); } qbr_VendTable = qbds_VendTable.addRange(fieldNum(VendTable, InventSiteId)); qbr_VendTable.status(RangeStatus::Hidden); qbr_VendTable.value(SysQuery::valueEmptyString()); } } } }} Источник: https://dynamicsaxinsight.com/2024/0...ecuting-event/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
Опции темы | Поиск в этой теме |
Опции просмотра | |
|