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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Creating Cascading Dro...
Power Apps
Suggested Answer

Creating Cascading Drop Downs with filtering based on child records

(1) ShareShare
ReportReport
Posted on by 26 Season of Giving Solutions 2025

Hello All

I have a Model-Driven App with a Timesheet Entry form I am developing for a law firm that contains lookup fields for Client and Matter.

  • The Client and Matter tables are related: the Matter table (cr4cc_xmatter) has a lookup to Client (cr4cc_client).

  • Each Matter has a status field (cr4cc_currentstatus), where 1 = Active and 0 = Passive



  •  

I want the Client lookup field on the Timesheet Entry form to show only those Clients who have at least one related Matter where cr4cc_currentstatus = 1 (i.e., only Clients with at least one Active Matter).


     

I tried adding a custom JavaScript function to the Timesheet Entry form to filter the Client lookup dynamically.I registered this function on the form’s OnLoad event and on the Client field’s PreSearch event.   I highlighted "Pass execution context as first parameter" checkbox.


Here’s the code I used:

function filterClientLookup(executionContext) {
    var formContext = executionContext.getFormContext();
    formContext.getControl("cr4cc_client").addPreSearch(function () {
        var fetchXml =
            "<filter type='exists'>" +
                "<entity name='cr4cc_xmatter'>" +
                    "<filter type='and'>" +
                        "<condition attribute='cr4cc_client' operator='eq' uitype='cr4cc_xclient' value='{GUID}' />" +
                        "<condition attribute='cr4cc_currentstatus' operator='eq' value='1' />" +
                    "</filter>" +
                "</entity>" +
            "</filter>";
        formContext.getControl("cr4cc_client").addCustomFilter(fetchXml);
    });
}

Can anybody help me how I can create a cascading drop down with this kind of filtering ?  

  • Has anyone successfully implemented a lookup filter based on the existence of related records in a Model-Driven App using JavaScript?

  • Is my FetchXML filter incorrect for this scenario? Do I need to pass a dynamic GUID, or use a different FetchXML structure for the addCustomFilter method?

  • Is there a better supported way to accomplish this (e.g., plugin, Power Automate, calculated field)?


  •  

 

Error Log

TypeError: formContext.getControl is not a function
    at filterClientsWithActiveMatters (https://org3de7bd99.crm4.dynamics.com/%7b000000005213037%7d/webresources/cr4cc_activematterclient:3:38)
    at b._executeFunctionInternal (https://content.powerapps.com/resource/uci-infra-web/scripts/app.035e5a081da0f65921241b47c8547fc5.js:14:1281338)
    at b.execute (https://content.powerapps.com/resource/uci-infra-web/scripts/app.035e5a081da0f65921241b47c8547fc5.js:14:1279772)
    at https://content.powerapps.com/resource/uci-infra-web/scripts/app.035e5a081da0f65921241b47c8547fc5.js:4:102401
    at a (https://content.powerapps.com/resource/uci-infra-web/scripts/app.035e5a081da0f65921241b47c8547fc5.js:14:101924)
    at re._executeIndividualEvent (https://content.powerapps.com/resource/uci-infra-web/scripts/app.035e5a081da0f65921241b47c8547fc5.js:4:102375)
    at re._executeEventHandler (https://content.powerapps.com/resource/uci-infra-web/scripts/app.035e5a081da0f65921241b47c8547fc5.js:4:99151)
    at Object.execute (https://content.powerapps.com/resource/uci-infra-web/scripts/app.035e5a081da0f65921241b47c8547fc5.js:4:96204)
    at w._executeSyncAction (https://content.powerapps.com/resource/uci-infra-web/scripts/app.035e5a081da0f65921241b47c8547fc5.js:14:630744)
    at w._executeSync (https://content.powerapps.com/resource/uci-infra-web/scripts/app.035e5a081da0f65921241b47c8547fc5.js:14:630471)
Error Details:
Event Name: onload
Function Name: filterClientsWithActiveMatters
Web Resource Name: cr4cc_activematterclient
Solution Name: Active
Publisher Name: DefaultPublisherorg3de7bd99
Categories:
I have the same question (0)
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,963 Moderator on at
     
    I believe the issue you are facing is that the getControl is not supported on the control you are attempting to use it on, hence that specific error.
     
     
    If these suggestions help resolve your issue, Please consider Marking the answer as such and also maybe a like.
    Thank you!
    Sincerely, Michael Gernaey

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 842

#2
Valantis Profile Picture

Valantis 563

#3
Haque Profile Picture

Haque 402

Last 30 days Overall leaderboard