Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Answered

Apply dynamic filter to subgrid in model-driven app using Javascript

(0) ShareShare
ReportReport
Posted on by 96

Hi,

 

I have a form for the table Project on which I have a subgrid for the table Objective (through one of its views). Objective has a lookup field for Phase. I want to apply a FetchXml query to the subgrid to filter on a specific Phase. I am able to find both the lookup string (eg. "Exploration") and the GUID stored in the Phase column of Objective referring to the lookup string. Right now I'm just trying to hard code the FetchXml string to filter the subgrid. This is what I've got:

 

SubGridFilterExecution = function (executionContext) {
	var formContext = executionContext.getFormContext();
	var gridContext = formContext.getControl("Subgrid_objectives");

			var FetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
			"<entity name='cr047_objective'>" +
			"<attribute name='cr047_Name' />" +
			"<attribute name='cr047_Description' />" +
			"<attribute name='cr047_Objectivemet' />" +
			"<attribute name='cr047_Mandatory' />" +
			"<filter type='and'>" +
			"<condition attribute='cr047_phase' operator='eq' value='{1c73-35c2-ec11-983f-6045bd948406}' />" +
			"</filter>" +
			"</entity>" +
			"</fetch>";

	gridContext.setFilterXml(FetchXml);
	formContext.getControl("Subgrid_objectives").refresh();
}

 

This renders zero rows in the subgrid. Removing the <filter> part of the string returns all rows, so the overall mechanics of the script seems to be OK.

 

Any help greatly appreciated!

 

 

  • NPrice99 Profile Picture
    1,292 on at
    Re: Apply dynamic filter to subgrid in model-driven app using Javascript

    Hi

    How do I Wire this into my Grid ?

     

    Thanks

     

    Nigel

  • rameshmukka Profile Picture
    1,089 on at
    Re: Apply dynamic filter to subgrid in model-driven app using Javascript

    @Rydman Do you know in similar context, how to get Main Grid context using Javascript. Your example is demonstrating about subgrid. I am struggling to get the main grid context and get FecthXML from main grid context. Let me know please.

     

    Thanks

    Ramesh Mukka

  • AnandM Profile Picture
    41 on at
    Re: Apply dynamic filter to subgrid in model-driven app using Javascript

    Hi @Rydman , 

    Can we use this undocumented method in our implementations? 

  • Verified answer
    Rydman Profile Picture
    96 on at
    Re: Apply dynamic filter to subgrid in model-driven app using Javascript

    Hi,

     

    My code is OK except for one small detail. My now working code looks like below. The only difference is that the curly brackets from the GUID are gone. Next step is to retrieve the GUIDs dynamically, but I'll google that before turning to the community 🙂

     

    SubGridFilterExecution = function (executionContext) {
    
    
    	var formContext = executionContext.getFormContext();
    	var gridContext = formContext.getControl("Subgrid_objectives");
    
    			var FetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
    			"<entity name='cr047_objective'>" +
    				"<attribute name='cr047_Name' />" +
    				"<attribute name='cr047_Description' />" +
    				"<attribute name='cr047_Objectivemet' />" +
    				"<attribute name='cr047_Mandatory' />" +
    				"<filter type='and'>" +
    					"<condition attribute='cr047_phase' operator='eq' value='82ed1c73-35c2-ec11-983f-6045bd948406' />" +
    				"</filter>" +
    			"</entity>" +
    			"</fetch>";
    
    	gridContext.setFilterXml(FetchXml);
    	formContext.getControl("Subgrid_objectives").refresh();
    
    
    
    }

     

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 85 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 65 Super User 2025 Season 1

#3
mmbr1606 Profile Picture

mmbr1606 55 Super User 2025 Season 1

Overall leaderboard