我有PDF URL需要使用javascript附加到我的Notes区域。我试过下面的代码,但它没有用。它表示PDF在打开PDF时已损坏。 Notes已创建,但是当我单击PDF附件时。打开时会抛出损坏文件的错误。
function CreateNotes()
{
var Annotation = new Object();
Annotation.ObjectId = { LogicalName: "quote", Id: RecordId, Name: "" };
Annotation.Subject = "Quote Report";
Annotation.NoteText = "Downloaded Today";
Annotation.FileName = "Quote.pdf";
var PDFContentBase64 = btoa(unescape(encodeURIComponent(PDFURL)));
Annotation.DocumentBody = PDFContentBase64;
Annotation.MimeType = "application/pdf";
createRecordSync(Annotation,"AnnotationSet");
}
function createRecordSync(entityObject, odataSetName) {
var jsonEntity = window.JSON.stringify(entityObject);
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
var createRecordReq = new XMLHttpRequest();
var ODataPath = getServerUrl() + ODATA_ENDPOINT;
createRecordReq.open("POST", ODataPath + "/" + odataSetName, false);
createRecordReq.setRequestHeader("Accept", "application/json");
createRecordReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
createRecordReq.send(jsonEntity);
var newRecord = JSON.parse(createRecordReq.responseText).d;
return newRecord;
}
function getServerUrl() {
return Xrm.Page.context.getClientUrl()
}
答案 0 :(得分:0)
CRM中的注释不能包含指向外部资源的链接。
您可以将整个PDF转换为base64并使用您当前使用的方法将其存储在CRM中,但它似乎不是您正在做的事情(encodeURIComponent(PDFURL)仅对URI进行编码 - 它实际上并没有获取PDF本身。)
如果您确实想要将整个PDF存储在CRM中,则需要获取PDF本身并对其进行base64编码。