giovedì 3 settembre 2026

D365FFO - Custom lookup su reference group

Con questo pezzo di codice possiamo effettuare la lookup custom su un controllo di tipo "Reference group":

 class LILCustFormletterParametersFormEH  
 {  
   [FormControlEventHandler(formControlStr(CustFormletterParameters, LILTaxRegistrationTypeApplicabilityRuleRefRecId), FormControlEventType::Lookup)]  
   public static void LILTaxRegistrationTypeApplicabilityRuleRefRecId_OnLookup(FormControl sender, FormControlEventArgs e)  
   {  
     SysReferenceTableLookup   sysReferenceTableLookup = SysReferenceTableLookup::newParameters(tableNum(TaxRegistrationTypeApplicabilityRule), sender, true);  
     Query            query = new Query();  
     QueryBuildDataSource    qbdsTaxRegistrationTypeRules = query.addDataSource(tableNum(TaxRegistrationTypeApplicabilityRule));  
             
     qbdsTaxRegistrationTypeRules.addRange(fieldNum(TaxRegistrationTypeApplicabilityRule, CountryRegionId)).value(queryValue(CompanyInfo::find().postalAddress().CountryRegionId));  
     qbdsTaxRegistrationTypeRules.addRange(fieldNum(TaxRegistrationTypeApplicabilityRule, PartyTypeRestriction)).value(queryValue(PartyTypeRestriction::None));  
     qbdsTaxRegistrationTypeRules.addRange(fieldNum(TaxRegistrationTypeApplicabilityRule, IsPrimaryAddressRestricted)).value(queryValue(NoYes::No));  
             
     sysReferenceTableLookup.addLookupField(fieldNum(TaxRegistrationTypeApplicabilityRule, TaxRegistrationType));  
     sysReferenceTableLookup.addLookupField(fieldNum(TaxRegistrationTypeApplicabilityRule, CountryRegionId));  
             
     sysReferenceTableLookup.parmQuery(query);  
     sysReferenceTableLookup.performFormLookup();  
             
     FormControlCancelableSuperEventArgs cancelableSuperEventArgs = e as FormControlCancelableSuperEventArgs;  
     cancelableSuperEventArgs.CancelSuperCall();  
   }  
 }