web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to Filter Self-Referencing Many-to-Many Lookup in Editable Subgrid in Dynamics 365

(4) ShareShare
ReportReport
Posted on by 227

I'm working with an editable subgrid in Dynamics 365 and need to filter a lookup column that has a many-to-many self-referencing relationship. Here's my scenario:

 

Setup:

 

  • I have a parent entity with a one-to-many relationship to a child entity

  • The child entity is displayed in an editable subgrid on the parent form

  • The child entity has a many-to-many relationship with itself (self-referencing N:N)

  • In the editable subgrid, there's a lookup column that allows selecting other records from the same child entity


  •  
 

Requirement:
When users click on the self-referencing lookup in the editable subgrid, I want to filter it to show only child records that belong to the same parent record. Essentially, when working within a parent record's subgrid, users should only be able to create many-to-many relationships between child records that share the same parent.

 

What I've Tried:

 

  1. Attempted to use addPreSearch, addCustomFilter, and removePreSearch methods in the OnRecordSelect event of the editable subgrid

  2. Tried using addCustomView to set a filtered view

  3. All these standard lookup filtering methods that work on regular forms don't seem to be available on lookup controls within editable subgrids
I have the same question (0)
  • Verified answer
    Nithin Krishna Bollineni Profile Picture
    34 on at
    Editable subgrid lookup columns do not support form script events like addPreSearch or addCustomFilter. The lookup control in the subgrid is rendered differently and does not fire the same JavaScript events as form lookups. addCustomView is also not available for editable subgrid lookup columns.
     
    Power Apps Component Framework (PCF) controls can be used to replace the out-of-box lookup column in the editable subgrid. With a custom PCF control, you can programmatically filter the records using Web API queries, and display only those child records related to the current parent. This is the recommended approach if inline editing and filtering are both required.
     
    Or else it is better disabling the editable subgrid and using a regular subgrid + lookup on the main form, where filtering is supported. This sacrifices inline editing but allows standard filtering.
  • Suggested answer
    Inogic Profile Picture
    686 on at
    Hi,
     
    You're running into a known limitation in Dynamics 365 — editable subgrids do not support standard client-side filtering methods like addPreSearch, addCustomFilter, or addCustomView for lookup columns.
    Editable subgrids render differently than standard form controls. Lookup fields within these subgrids are not fully accessible via form scripting. As a result:
    • addPreSearch and addCustomFilter do not apply to subgrid lookups.
    • There is no getControl available directly on subgrid columns to attach filters.
    • The OnRecordSelect event is useful for row-level logic but does not allow you to dynamically filter lookup fields in place.
    Workarounds to Achieve the Desired Filtering:
    Option 1: Use a Quick Create Form with a Standard Subgrid
    Instead of using an editable subgrid, switch to a regular subgrid and open records using a Quick Create or standard form. This allows you to use standard filtering methods on the lookup field.
    Steps:
    • Use a regular (non-editable) subgrid on the parent form.
    • Users can click "+ New" or open records in a Quick Create form.
    • In the Quick Create form for the child entity, apply your custom filter logic using addPreSearch or addCustomFilter on the self-referencing lookup field.
    This approach fully supports client-side filtering and allows you to restrict the lookup to child records with the same parent.
    Option 2: Implement a Custom PCF Control
    If inline editing is a must, developed a custom PCF control to replace the lookup column.
    Steps:
    • Replace the standard lookup column in the editable subgrid with a custom PCF control.
    • Use the Web API to fetch and filter related child records based on the current parent context.
    • Present the filtered list using a custom dropdown, search box, or other UI.
    This approach provides full flexibility and control over how the data is displayed and filtered.
    Hope this helps.
     
    Thanks!
    Inogic
  • Barış Kuzu Profile Picture
    227 on at
    @Nithin Krishna Bollineni

    I'll resort to PCF. Thank you.
  • Suggested answer
    Daniyal Khaleel Profile Picture
    752 Most Valuable Professional on at
    how to filter self referencing
     
    • Editable subgrid = uses the new Power Apps Grid control, which supports inline editing.

    • Lookup filtering must be done using JavaScript + addOnLookupTagClick or custom JavaScript filtering via formContext.getControl().addPreSearch().

    •  As of now, the standard addPreSearch() approach works only in form-level lookups, not directly in Power Apps editable subgrid lookups.




    •  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 144 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 59

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans