Skip to content

FetchXML Generator

Peter McDonald edited this page Aug 12, 2026 · 2 revisions

FetchXML Generator

Run and edit the FetchXML that is already in your C#, TypeScript or JavaScript. A CodeLens appears above the query, runs it against your environment, and opens a visual generator that writes your edits back into the same string literal.

Preview feature. Tick Preview features in the panel footer to switch the query tools on.

1. Find the query

Open a file containing FetchXML. A lens appears above the literal: Run, Edit in generator, and an issue count when there is something to check.

The Run, Edit in generator and issue-count CodeLens above FetchXML in a C# file

Recognised without any configuration:

Language Forms
C# verbatim (@"…"), interpolated ($@"…"), raw ("""…"""), and + concatenation
TypeScript / JavaScript template literals, quoted strings, and + concatenation

Click the issue count to see the details. Any value your code interpolates into an attribute is flagged so you can check it is escaped — a quote or an & in the value would otherwise break the query:

The issues lens on a TypeScript template literal with an unescaped interpolated value

2. Run it

Click Run. Anything your code interpolates into the query is a placeholder, and you are asked for a value before the query runs:

The prompt asking for the placeholder's value before the query runs

The expected type comes from the column in the condition, so a Uniqueidentifier column rejects anything that is not a GUID and a whole-number column rejects text.

3. Read the results

Results open beside your code, with the row count and the environment and user the query ran as. Your query runs as you here, so row-level security and eq-userid may resolve differently at runtime.

The results view showing returned rows

Use Copy as CSV, Copy as JSON or Copy FetchXML along the bottom.

4. Edit it

Click Edit in generator.

The FetchXML Generator: the query tree, the properties panel, the FetchXML text and the parameters

Area Use
Tree Select an element to edit it; add and remove entities, attributes, filters, conditions and links from the controls beneath
Properties The attributes the selected element supports, each with what it does and what it cannot be combined with
FetchXML The query as it currently stands
Parameters Your placeholders, named after the variables in your code

Run runs the edited query without changing your file. Reload metadata re-reads tables and columns after a schema change. Copy FetchXML puts the query on the clipboard.

5. Save it back

Save to code rewrites the string literal in place. Your placeholders go back as the code expressions they came from, the rest of the file is untouched, and an edit that changes nothing writes nothing.

Re-open the lens and the generator reads the same query back.

Where FetchXML can be used

Consumer How it takes FetchXML
Plug-in / workflow (SDK) new FetchExpression(xml) — full FetchXML including aggregates and link-entity
Web resource / PCF Xrm.WebApi.retrieveMultipleRecords(entity, "?fetchXml=" + encodeURIComponent(xml))
Saved view The view's fetchxml column — no placeholders, a view cannot prompt
Lookup filter A <filter> fragment, not a whole <fetch>
Portals / Power Pages Liquid {% fetchxml %}

The generator flags anything the surrounding consumer cannot accept — an aggregate in a lookup filter, for instance — while you are editing.

Troubleshooting

Problem Fix
No lens on a query Tick Preview features in the panel footer. The text also has to parse as FetchXML — a malformed fragment reports an issue instead
"Connect to Dataverse first" Running needs a live connection; editing does not
Tables or columns look stale Reload metadata in the generator toolbar
The prompt rejects your value The type comes from the column in the condition — check its attribute

See also

Clone this wiki locally