rappen / FetchXMLBuilder

FetchXML Builder for XrmToolBox and Microsoft Dynamics 365 / CRM
https://fetchxmlbuilder.com/
GNU General Public License v3.0
135 stars 56 forks source link

Only the first 5000 views are retrieved from Dataverse #831

Closed ryanspain closed 1 year ago

ryanspain commented 1 year ago

Problem

When the Select View dialog data is being hydrated, only the first 5000 views from the target environment are retrieved, order descending by name. This leaves view 5001+ excluded from the View selector.

image

I'm working in an environment that has over 5000 views (savedqueries). I need to name my views wisely to have them appear in Fetch XML Builder :)

Cause

The RetrieveMultiple(QueryBase query) called by LoadViews in FXBQueries.cs is handing off to the service clients RetrieveMultiple method which by default does not handle pagination where more results exist.

Solutions

I see 2 solutions here:

  1. Update the LoadViews to use a Fetch XML query to retrieve system views by making use of RetrieveMultiple(string fetch) instead of the QueryBase version.
  2. Update the RetrieveMultiple(QueryBase query) method to support pagination as described in Working with more than 5,000 records in Dynamics 365 . Note it would only need to work for QueryExpression and QueryByAttribute types.

Next steps

I'm happy to submit a PR to address this. Thoughts?

rappen commented 1 year ago

Ah. Nice bug found. I'd love a PR!

Will your PR give more/better than this? 😉 (Sorry, I had to find an easy solution...)

image image

rappen commented 1 year ago

Just wondering... Why do you have 5000+ views?? 😲

ryanspain commented 1 year ago

@rappen, it might be easier to just use Fetch XML to retrieve the views because pagination already implemented in RetrieveMultiple(string fetch) as the default behavior. The query isn't complex.

But I'm also in favor of updating RetrieveMultiple(QueryBase query) to, by default, include all records. Less records can be returned by setting the PageInfo.Count for the query being passed in. The need for an allRecords flag or similar could then be removed.

I have an IOrganizationService.RetrieveMultipleRecursively(QueryBase query) extension method I use for scenarios like this. It could be dropped into RetrieveMultiple(QueryBase query).

I'll work on a PR for this at the weekend.

ryanspain commented 1 year ago

If I can figure out why there are 7079 views in this environment @rappen, I'll let you know.

For now, it remains a mystery 🔮

As a comparison though, a vanilla Dataverse environment (No first-party apps) contains 1688 views as of today.

rappen commented 1 year ago

I guess your extension is like this, right? https://github.com/rappen/Rappen.XTB.Helper/blob/main/Rappen.XRM.Helpers/Extensions/ServiceExtensions.cs#L51-L79

ryanspain commented 1 year ago

Exactly. I guess that makes this easier given this repo references Rappen.XRM.Helpers as a submodule! Nice one.

rappen commented 1 year ago

So I go back to my previous suggestion.... 😉