Wednesday, 26 July 2017

{Know-how} Dynamics 365 - SSRS pass prefiltering report parameter and open report using URL - JavaScript

Reporting is an essential part in any system. In Dynamics CRM, we have wide variety of reporting options that are flexible enough to meet most of the requirements and one such scenario is explained here. At times we may need to open a report via URL inside an IFrame or in a new window based on the requirement and in our scenario it is new window.

On click of a ribbon button in an account record, open account prefiltered report in a new window.

Code Explanation:
To form a report URL we need following
  1. Organization URL - Organization URL  and in my case
  2. Report Id- unique identifier of the report
  3. Action - It can be either run or filter and for our scenario it should be run
  4. Context - It should be records
  5. ETC - Entity type code and in our case its for account
  6. Record Id - unique identifier of the current record
Note: The parameters 4,5 and 6 are specific to prefiltering. Skip the same if you want to run a report without preregistering

JavaScript code snippet:
             var orgUrl = Xrm.Page.context.getClientUrl();  
             var action = "run";  
             var context = "records";  
             var reportId = "report id goes here";
             var recordid ="{", "").replace("}", "");  
             var etc = Xrm.Page.context.getQueryStringParameters().etc;  
             var url = orgUrl +  
               "/crmreports/viewer/viewer.aspx?action=" + encodeURIComponent(action) +  
               "&context=" + encodeURIComponent(context) +  
               "&id=%7b" + encodeURIComponent(reportId) + "%7d" +  
               "&records=%7b" + encodeURIComponent(recordid) + "%7d" +  
               "&recordstype=" + encodeURIComponent(etc);  
             var customParameters = encodeURIComponent(url);  
             Xrm.Utility.openWebResource("reportcontainer.html", customParameters)  

HTH! Please leave your valuable feedback in comments!


  1. Hi, were you able to generate a pdf file from a button from a SSRS report in Dynamics V9?


    1. You can use sessionid and controlid to generate PDF file from SSRS report. Refer


Contact Form


Email *

Message *