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

Notifications

Announcements

No record found.

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);
}
}

I have the same question (0)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 70

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans