knowledgecenter-breadcrum

Knowledge Center

10 Nov, 2020

How to convert SSRS report in word format using JavaScript?

Posted on 10 Nov, 2020 by Admin, Posted in Dynamics 365 Dynamics-365 Sales

How to convert SSRS report in word format using JavaScript? Blogs

How to convert SSRS report in word format using JavaScript?

Introduction

In this blog, I am going to explain how we can export SSRS reports as Word Document. To know how we can execute SSRS reports, you can refer below blog:

https://themscrmexpert.wordpress.com/2016/12/19/how-to-send-ssrs-report-as-a-pdf-in-email-in-dynamics-crm-online/

Solution

To get SSRS report in word format, first we need to execute SSRS report, you can refer above link to execute report. Then we will get the response in which we will get ReportSession and ControlID. We will need these report session and control id to generate word document version of SSRS report.

Now, create a query string to get word version of SSRS report as follows:

let queryString = [Organization URI] + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + ReportSession + "&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + ControlID + "&OpType=Export&FileName=public&ContentDisposition=OnlyHtmlInline&Format=DOCX";

Now, create request object that will be called to convert the response in DOCX base64 string:

function fnConvertReportToWord(queryString){
 var retrieveEntityReq = new XMLHttpRequest();
 retrieveEntityReq.open("GET", queryString, true);
 retrieveEntityReq.setRequestHeader("Accept", "*/*");
 retrieveEntityReq.responseType = "arraybuffer";
 retrieveEntityReq.onreadystatechange = function () { // This is the call-back function.
 if (retrieveEntityReq.readyState == 4 && retrieveEntityReq.status == 200) {
   var binary = "";
   var bytes = new Uint8Array(this.response);
   for (var i = 0; i < bytes xss=removed xss=removed xss=removed>[removed] + base64WordString;
   //open or download report in word format
   window.open(base64DataUrl);
 }
};
//This statement sends the request for execution asynchronously. Callback function will be called on completion of the request.
retrieveEntityReq.send();
}

You will get a data URL base64DataUrl of word version of SSRS report to print or download report in word format. You can use base64WordString to attach as an email attachments and send report as word document.

Comment

This is a Required Field

Loading

Recent Updates

Blogs
07 Sep, 2023

Optimizing Storage with SubscriptionTrackingDeletedObject Cleanup

What is SubscriptionTrackingDeletedObject? The "SubscriptionTrackingDeletedObject" table is linked to the "DeletionService," which handles two types of cleanup: organization-wide and record-specific.…

READ MORE
Blogs
05 Sep, 2023

How to create real-time customer journeys in Dynamics 365 Marketing

Introduction: This blog will show how to create real-time customer journeys in Dynamics 365 Marketing. Customer journeys can be either…

READ MORE
Blogs
30 Aug, 2023

D365 CUSTOMER SERVICE: CUSTOMER 360 COMPONENT

Introduction: In Dynamics 365 (D365) Customer Service, the 'Customer 360' Component provides a comprehensive view of information and enables users…

READ MORE