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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Apply dynamic filter t...
Power Apps
Unanswered

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!

 

 

I have the same question (0)
  • Verified answer
    Rydman Profile Picture
    96 on at

    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();
    
    
    
    }

     

  • AnandM Profile Picture
    41 on at

    Hi @Rydman , 

    Can we use this undocumented method in our implementations? 

  • rameshmukka Profile Picture
    1,115 on at

    @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

  • NPrice99 Profile Picture
    1,302 on at

    Hi

    How do I Wire this into my Grid ?

     

    Thanks

     

    Nigel

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard