How to Fix SharePoint CAML Query Returning Folders Instead of List Items
Question details
The user needs to retrieve specific list items via a CAML query without fetching the parent folders or receiving null values for custom fields.

- Product
- SharePoint Online
- Device & OS
- not provided
- Scenario
- Executing a SharePoint GetItems CAML query to retrieve list items that contain custom fields like FirstName, LastName, and Manager.
- Observed behavior
- The query returns folders and more items than expected. Only the Title field is populated, while the custom fields return as null.
Ensure you have access to the codebase or the query editor where your SharePoint CAML queries are constructed and executed.
Add the RecursiveAll Scope to the CAML View Element
By modifying the scope of the CAML query, you force SharePoint to bypass the default root-folder limitation and traverse the entire list hierarchy to fetch actual items.
By default, SharePoint queries often search only the root folder level, which is why your query is returning the folders themselves rather than the items inside them. This also explains why custom fields are null—folders generally only populate the Title field.
Adding the RecursiveAll scope ensures that the query traverses all folders and subfolders to fetch the specified list items alongside their populated custom fields.
Open your development environment or query editor and navigate to the specific CAML query string used for the GetItems request.
Identify the <View> XML tag wrapping your query parameters.
Add the Scope attribute to the View tag so it reads: <View Scope="RecursiveAll">.
To prevent list view threshold errors, ensure you have a reasonable row limit defined within the view, such as <RowLimit>5000</RowLimit>.
Run the query again. The folders will be bypassed, and the custom fields like FirstName, LastName, and Manager should now be populated properly.

Analyze Exported SharePoint Lists with WPS Office
While resolving complex SharePoint development queries, you might frequently need to verify exported list data. WPS Office provides a free, lightweight, and highly compatible alternative to Microsoft Office for analyzing CSV and Excel files exported directly from SharePoint.
- 1. Download WPS Office: Get the free WPS Office suite from the official website and install it on your computer.
- 2. Export SharePoint Data: From your SharePoint list, use the 'Export to Excel' or 'Export to CSV' function to download your queried data.
- 3. Open and Analyze: Double-click the downloaded file to open it seamlessly in WPS Spreadsheet for data formatting and analysis.

Frequently Asked Questions
Why do custom SharePoint fields return as null in my CAML query?
This usually happens when the query retrieves folder objects instead of actual list items. Folders do not inherently contain your custom item fields (like FirstName or Manager), so only the Title field populates. Using the RecursiveAll scope targets the items inside the folders instead.
What is the difference between Recursive and RecursiveAll in a CAML query?
The 'Recursive' scope fetches all list items across all folders but excludes the folders themselves from the results. 'RecursiveAll' fetches all list items and all folders across the entire document library or list hierarchy.
Does changing the RowLimit solve the folder return issue?
No, the RowLimit tag only restricts the maximum number of items or folders returned in a single batch to avoid threshold errors (e.g., the 5000 item limit). The Scope attribute is what dictates whether folders or their contents are retrieved.




