Wednesday, 23 June 2021

Customized lookup for form datasource field

class PurchtableFormEventHandler { [FormDataSourceEventHandler(formDataSourceStr(PurchTable, InventDim), FormDataSourceEventType::Initialized)] public static void InventDim_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e) { var overrides = PurchReqTableFormExtensionOverrides::construct(); sender.object(fieldNum(InventDim, InventSiteId)).registerOverrideMethod(methodStr(FormDataObject, lookup), methodStr(PurchReqTableFormExtensionOverrides, InventSiteId_OnLookup), overrides); } } ================================================================================================== public class PurchReqTableFormExtensionOverrides { protected void new() { } public static PurchReqTableFormExtensionOverrides construct() { return new PurchReqTableFormExtensionOverrides(); } public void InventSiteId_OnLookup(FormStringControl _callingControl) { String255 sUserId = curUserId(); HcmWorkerRecId workerRecId = HcmWorker::findByPerson(DirPersonuser::find(sUserId).PersonParty).RecId; SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(EmployeesSites), _callingControl); Query query= new Query(); QueryBuildDataSource qbds = query.addDataSource(tableNum(EmployeesSites)); qbds.addRange(fieldNum(EmployeesSites, EmployeeID)).value(queryValue(workerRecId)); qbds.addRange(fieldNum(EmployeesSites, Company)).value(curExt()); sysTableLookup.addLookupfield(fieldNum(EmployeesSites, SiteId)); sysTableLookup.addLookupfield(fieldNum(EmployeesSites, SiteName)); sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); } }