Using Xrm.Navigation.openFile to download a note attachment file with file save confirmation dialog

Debajit's Dynamic CRM Blog

I got this requirement recently and wanted to share with my readers. Quite a cool feature actually and some common requirement. So there is a ribbon button on a entity form. When the ribbon button is clicked, it should query an annotation attachment, get the content and then throw the file save dialog option to the user to save or open the file.

Querying the annotation record is piece of cake after all. The interesting part is throwing the filesave dialog option.

Below is the code on click of the ribbon button which does exactly that.

function DownloadAnnotationRecord() {
Xrm.WebApi.retrieveRecord(“annotation”, “<annotation_record_id>”, “?$select=filename,filesize,documentbody,mimetype”).
then(function (r) {
var fileOptions = {
fileContent: r.documentbody,
fileName: r.filename,
mimeType: r.mimetype

var openOptions = { openMode: 2 };

Xrm.Navigation.openFile(fileOptions, openOptions)
.then(function () {
console.log(“File downloaded successfully.”);
}, function () {

View original post 47 more words

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website at
Get started
%d bloggers like this: