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

Dynamic Fetch on Subgrid returning blank Javascript

(0) ShareShare
ReportReport
Posted on by 188
Good Morning, 
I've been having a lot of issues with this Javascript solution.
The primary goal is to have a subgrid on a separate tab that will give us a view into another entity.  The Ideas is to Dynamically set the fetch to this subgrid based on values of Custom Entity lookups on the case form.  However, when its ran it returns blank even though I've verified that Items exist.  Below is my code.
 
function CustEntity1_refresh(executionContext){    var formContext = executionContext.getFormContext();    var Custentity2 = formContext.getAttribute('Cust_entity2').getValue();   // get the subgrid controlvar subGridControl = formContext.getControl(/Case_CustEntity1/);// get the view associated with the subgrid control//var viewId = subgridControl.getViewId();var custEntity2Id=Custentity2[0].id;alert(custEntity2Id);custEntity2Id=custEntity2Id.replace(/{/,//);alert(custEntity2Id);custEntity2Id=custEntity2Id.replace(/}/,//);alert(custEntity2Id);// set the fetchxml query for the view, filtering based on your criteria var fetchXml = /<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>/+/<entity name='cust_entity1'>/+/<attribute name='cust_name' />/+/<attribute name='cust_entity2' />/+/<attribute name='createdon' />/+/<attribute name='cust_entity3' />/+/<attribute name='cust_entity1Id' />/+/<order attribute='cust_name' descending='false' />/+/<filter type='and'>/+ /<condition attribute='statecode' operator='eq' value='0' />/+/<condition attribute='cust_entity2' operator='eq'  uitype='cust_entity2' value='/+ custEntity2Id.toLowerCase() + /'/>/+ /</filter>/+/</entity>/+/</fetch>/;alert(fetchXml);// set the view XML of the subgrid with updated filter criteriasubGridControl.setFilterXml(fetchXml); formContext.getControl(/Case_Custentity1/).refresh();alert(formContext.getControl(/Case_Custentity1/).getFetchXml());}function callBackFunction(result) {if (result == 'success') {} else {} }
 
    For the above code(various references changed for anonymity sake), I've been able to receive all alerts which tells me there isn't a compilation or syntax error. 
Using the alert(fetchXml) I was able to grab the fetch generated and after converting single quotes to double quotes was able to get return records using the XRM toolbox Fetch XML tester. This tells me that the fetch isn't bad.
I am seeing the view switch from its default view to blank so this tells me I'm using the right control name and am targeting the right control.
However, one thing I do find interesting is that the last alert returns Null. 
This has got me stumped. If anyone has any suggestions it would be greatly appreciated. 
I have the same question (0)
  • Suggested answer
    Alex KaSi Profile Picture
    41 on at
    Try setting the fetch without any filters, to check if there's the problem
  • Verified answer
    Jerett Crumbley Profile Picture
    188 on at
    What I discovered through a separate forum is that the SetFilterXML would only receive the filter portions of the fetch and ultimately i was trying to set the whole Fetch XML there.  This was causing my issue. 

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 72 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans