web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

How to convert SSRS report in word format using JavaScript?

(0) ShareShare
ReportReport
Posted on by 5

Hi Team. I want to generate SSRS Reports in Microsoft Word document format and attach as a Note in custom entity. by using JavaScript. I have tried below code, but it did not work. Can any one suggests JavaScript for this.

function fnConvertReportToWord(projectId, formContext, reportGuid) {

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

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.byteLength; i++) {
binary += String.fromCharCode(bytes[i]);
}
//This is the base64 Word formatted string
var base64WordString = btoa(binary);
CreateConsolidateWordNoteUnderProject(base64WordString, projectId, formContext, reportGuid);

}
};
//This statement sends the request for execution asynchronously. Callback function will be called on completion of the request.
retrieveEntityReq.send();

}

function CreateConsolidateWordNoteUnderProject(data, projectId, formContext, reportGuid) {
try {

var fileName = "Test";

//deleteAttachments(fileName);
var entity = {};
entity.documentbody = data;
entity.objecttypecode = 'new_customerEntity';
entity["objectid_customerEntity@odata.bind"] = "/new_customerEntitys(" + projectId + ")";
entity.subject = fileName;
entity.filename = fileName;
//entity.mimetype = "application/pdf";
//entity.mimetype = "application/msword";
entity.mimetype = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
var globalContext = Xrm.Utility.getGlobalContext();
var req = new XMLHttpRequest();
req.open("POST", globalContext.getClientUrl() + "/api/data/v8.2/annotations", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
var uri = this.getResponseHeader("OData-EntityId");
var regExp = /\(([^)]+)\)/;
var matches = regExp.exec(uri);
var newEntityId = matches[1];
formContext.data.refresh(true);

} else {
console.log(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
}
catch (error) {
HideLoading();
Console.log("Error in createConsolidateNote JS Error: " + error.message);
}
}

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Syed Aqib Raza Profile Picture

Syed Aqib Raza 125

#2
ParthPatel249 Profile Picture

ParthPatel249 87

#3
11manish Profile Picture

11manish 85 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans