Going Beyond Advanced Find, Views, and the XRMToolbox: Using FetchXML and Left Outer Joins

by | Updated June 21, 2018 | Dynamics CRM

Some days a request comes along for a view that goes beyond what the advanced find can generate.  Some examples are Aggregates, Left Outer Joins, or you simply might be joining entities in a way to display data that the Advanced Find doesn’t allow.  (Example:  Opportunity Line à Opportunity à Account.  We cannot display a column from the account entity.)  A great example of a Left Outer Join came across my desk recently for a client that wanted a view of “All Opportunities Without an Open Activity”.  Left outer joins are required when you are doing a “not in” query.

I took this opportunity to utilize a few items in the XRMToolbox to help me with this task.  I was already aware of the “FetchXML Tester” and after years away from it, it still worked like a charm.  I started by getting as far as I could with an Advanced Find Query and then downloading the FetchXML.

Beyond Advanced Find

I loaded the results into the FetchXML Tester and updated it to include the left outer join logic.  (NOTE:  If you are uncomfortable working with FetchXML by just typing it in, you might want to use the FetchXML Builder that I referenced in Part 2.)  To learn more about FetchXML and the left outer join, click here to see a Microsoft example.  Microsoft’s example is a little simpler and might be easier to follow.

FetchXML Tester

Beyond Advanced Find

There isn’t much to explain with this tool other than you can type FetchXML against your CRM Org and click the execute button to see the results in the next “Response” tab.  In the example above, I am excluding any task (entity name “activitypointer”) that is not open and displaying the task’s statecode.  (A task’s open state code = ‘0’.)

The last highlighted filter references the entity alias of “ab” and looks at the task’s statecode returned.  Any Opportunity that has a task of open will return a ‘0’.  All other Opportunites return a task statecode of null.  I only wanted the opportunities without an open task so I made sure this was null.

I click Execute and the Response tab shows my results.  The simplicity of the “FetchXML Tester” is what I like the most.  Connect to your org, type in your FetchXML, click Execute, and see your results.


Beyond Advanced Find

At this point, I had tested my XML and it was returning the data I wanted.  I now had to get my new query into the view in CRM.  Previously when I had to do this I had to:

  1. Add the View that I wanted to update to a new unmanaged solution
  2. Export the solution.
  3. Unzip the solution and open the customizations.xml file.
  4. Parse through the solutions XML and find the view with the FetchXML that I want to update.
  5. Manually modify the view with my new FetchXML.
  6. Save the customizations.xml file.
  7. Zip up the solution and re-import.
  8. Test and hope I did not make a typo.

There had to be a better way.  Good news is there was!  Next, on to Part 2 where we discuss the XRMToolbox “View Designer” and “FetchXML Builder.”

Related Posts


Submit a Comment

Your email address will not be published. Required fields are marked *

Upcoming Events


31mar01aprTraining Class: Financial Reporting W/Account Schedules for Dynamics 365 Business Central

07apr2:00 pm2:30 pmEnsuring Quality for Batch Manufacturers

08apr11:00 am12:00 pmConfab with Stoneridge - Livestream - Jumping into the Deep End of the Data Lake

14apr10:00 am10:30 amBoost Seller Productivity and Close More Business with Dynamics 365 Sales

21apr10:00 am10:30 amSetting Your Sales Team Up for Success: A Modern Look at Revenue Operations

21apr12:00 pm1:00 pmGetting Started with Barcode Scanners and WMS Apps for Business Central

21apr2:00 pm3:00 pmMoving to the Cloud: Today's Solution for Leading Field Service Companies

22apr11:00 am12:00 pmConfab with Stoneridge - Livestream - Moving from Manual to Automated with Strategic Automation Strategies

28apr10:00 am10:30 amThe Modern Manufacturer: Best Practices for Inventory Turnover

28apr12:00 pm1:00 pmPower Up Microsoft Dynamics by Automating Budgeting, Dashboarding and Reporting


05may10:00 am10:30 amAchieve More with Zetadocs for Business Central

05may2:00 pm2:30 pmSimplifying Item Pricing, Availability, and Tracing for Batch Manufacturers

06may11:00 am12:00 pmD365 Field Service – New Features to Empower Your Remote Workforce

12may10:00 am10:30 amThe Modern Manufacturer: Manufacturing Software in the Real World

12may12:00 pm12:30 pmFinancial Implications of Moving from Dynamics GP to Dynamics 365: Licensing and Infrastructure

17may(may 17)8:00 am28(may 28)11:00 amDynamics 365 Finance & Supply Chain Development Training - Online Workshop

26may10:00 am10:30 amThe Modern Manufacturer - Enterprise Asset Management

About Stoneridge
Stoneridge Software is a unique Microsoft Gold Partner, with emphasis on partner. With specialties in Microsoft Dynamics 365, Microsoft Dynamics AX, Microsoft Dynamics NAV, Microsoft Dynamics GP and Microsoft Dynamics CRM, we focus on attracting the most knowledgeable experts in the field to our team, and prioritize delivering stellar solutions with maximum impact for your business. At Stoneridge, we are deeply committed to your results. Each engagement is met with a dedicated team, ready to provide thorough, tailored, and expert service. Based in Minnesota, we intentionally “step into your shoes,” wherever you are. We focus on what you care about, and develop trusting, long-term relationships with our clients.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!