Here's my solution to the problem.
Except for jQuery, grab FileSaver.js, Blob.js and base64-binary.js.
Create your own download.js file as below, and add the addRequestDownloadLink-function to the OnLoad event of the form.
As the original license data is binary, you'll need to use Base64-binary.js instead of i.e. atob().
function addRequestDownloadLink() {
$('#my_download').append('<div id="my_download_downloadcontainer"><a href="#" id="my_download_requestdownload">Request download of license file</a></div>');
}
$('body').on('click', '#my_download_downloadlink', function() {
var str_decoded = Base64Binary.decode($(this).attr('data-license'));
var blob = new Blob([str_decoded], {type: "license/binary"});
saveAs(blob, $(this).attr('data-filename'));
});
$('body').on('click', '#my_download_requestdownload', function() {
var guid = Xrm.Page.data.entity.getId();
guid = guid.replace("{", ""); guid = guid.replace("}", "");
var filename = Xrm.Page.getAttribute("my_name").getValue() + ".dat";
var organization = Xrm.Page.context.getOrgUniqueName();
var entity = "my_license";
var select = "?$select=my_DataSigned"
var oDataSelect = "/" + organization + "/XRMServices/2011/OrganizationData.svc/" + entity + "Set(guid'" + guid + "')" + select;
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: oDataSelect,
beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
success: function (data, textStatus, XmlHttpRequest) {
if (data.d.my_DataSigned != null) {
$('#my_download_downloadcontainer').html('<a href="#" id="my_download_downloadlink" data-license="' + data.d.my_DataSigned + '" data-filename="' + filename + '">Download license file!</span>');
}
else {
alert("No license found!");
}
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);
}
});
});
Tadaaa! Hope this will help someone with the same issue.