Lookup field on a Dynamics 365 form – add filter
This post describes how a supervisor at Contoso Pharmaceuticals Limited can be added to a particular clinical trial. One particular requirement is that only supervisors listed in the ‘resources pool’ sub grid (Figure 2) can be selected as a supervisor.
Initially, the Supervisor lookup control (Figure 2) displayed all resource records in the entity cpl_resource which have the Position = Supervisor.
However, to meet the requirement, a second filter needed to be applied to this lookup so that it only displays resources from the ‘resources pool’ sub grid with the Position = Supervisor
First Approach – Related Records Filtering
To meet this requirement, I first tried filling out the ‘Related Records Filtering’ section of the Supervisor lookup control. Referring to Figure 3, note that ‘Resources (CTNumber)’ represents the ‘Resources Pool’ subgrid in Figure 2
This didn’t appear to work correctly. That is, ‘Test user1’ wasn’t the only supervisor appearing in the Supervisor lookup (Figure 4). (Note the Supervisor lookup control is defined as cpl_supervisorresource which is referenced in Figure 5. It’s a lookup to the cpl_resource entity)
Second Approach – addPreSearch & addCustomFilter
This worked as shown below
Note: One potential issue is that the browser may display previously entered values (e.g. Test user2 – Supervisor) for selection. To resolve this in the classic editor, select ‘Disable most recently used items for this field’