Granger
Granger

Reputation: 21

Lookup Filtering on D365 x++

I am a beginner at d365 finance and operations. I have service and sub-service lookup fields in a form. This field's data sources have a one-to-many relationship with a foreign key. When I select a record in the service field, I want to see only sub-services that belong to the selected 'service' record in the 'sub-services lookup field. I need a lookup filtering for this with X++ but I do not know-how. I would be really appreciated it if someone can help me with this.

Here is my code but I really confused all the tables and fields name and I probably write the wrong names in the wrong places.

//My main form that includes lookup fields is inventSite // Control names of lookup fields are InvenSite_ServiceRefRecId and InventSite_SubServiceRefRecId //The name of the form that includes service and subservice records is Service // the table that includes subservice records is SubService

Here is my Service form Service form

[FormControlEventHandler(formControlStr(InventSite, InventSite_SubServiceRefRecId), FormControlEventType::Lookup)]
   public static void InventSite_SubServiceRefRecId_OnLookup(FormControl sender, FormControlEventArgs e)
   {
       SysReferenceTableLookup sysRefTableLookup;
       Query query = new Query();
       QueryBuildDataSource qbds;

       FormRun formRun;
       FormControl formCtrl;
       ServiceName serviceName;
       FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;

       sysRefTableLookup = SysReferenceTableLookup::newParameters(tableNum(Service), sender);
       qbds = query.addDataSource(tableNum(Service));
       formRun = sender.formRun();

        
       formCtrl = formRun.design().controlName(formControlStr(InventSite, InventSite_SubServiceRefRecId));
       serviceName = formCtrl.valueStr();

       qbds.firstOnly(true);
       qbds.addRange(fieldNum(Service, ServiceName)).value(queryValue(serviceName));

       sysRefTableLookup.parmQuery(query);
       sysRefTableLookup.addLookupfield(fieldNum(Service, ServiceName));
       sysRefTableLookup.addLookupfield(fieldNum(Service, ServiceDescription));
        
       sysRefTableLookup.performFormLookup();

       ce.CancelSuperCall();
   }

Upvotes: 0

Views: 5131

Answers (1)

You need to overide lookup. Please find an example here in community blog. https://community.dynamics.com/365/financeandoperations/b/365foandaxtechnicalworld/posts/override-lookup-ax7-amp-d365fo

Upvotes: 0

Related Questions