Run Fetch XML Report on Selected Record in Dynamics CRM 2011

Paul Nieuwelaar, 19 December 2011

In Dynamics CRM 2011 when you are creating a Fetch XML report, you have the option to make the report available to run on a Selected Record. This means when you are viewing a report for a specific record (such as the Invoice report) the data that makes up the report will only be pulled from the context of the current (or selected) record.

You can see the different options available when you go to run a report. You can see 2 categories of reports: Run on Selected Records, or Run on All Records.

 Run Fetch XML Report on Selected Record in Dynamics CRM 2011

The first category is the one we’re interested in. To get your report into this category you need to have prefiltering enabled in your fetch XML query. When you ‘Download Fetch XML’ from an advanced find, prefiltering will not be added into your query by default.

To add prefiltering to your query, open the file containing your Fetch XML query. In Visual Studio right click the Dataset and select Query.

 Run Fetch XML Report on Selected Record in Dynamics CRM 2011

If the Report Data pane isn't displayed by default, click on View, and select Report Data, or press Ctrl + Alt + D.

In the Query Designer, add enableprefiltering=”1” to the first opening entity tag like follows.

Run Fetch XML Report on Selected Record in Dynamics CRM 2011

Click Ok. Save, Build, and upload your report .rdl file to CRM.

IMPORTANT: When you are adding the report into CRM, make sure you create a new report, and don’t re-upload the .rdl file to an existing report. The context in which the report is run (on all records or on selected records) does not change when you re-upload to an existing report.

Finally after uploading our report we can see the report showing up under the Selected Records category:

 Run Fetch XML Report on Selected Record in Dynamics CRM 2011

If we run the report from an open form, it will be run only on the current record. However if we run the report from a Grid view, we will be prompted to select whether to run the report on the selected records, or on all records in the view.

 Run Fetch XML Report on Selected Record in Dynamics CRM 2011