-
Notifications
You must be signed in to change notification settings - Fork 26
MobileCRM.DynamicEntity.downloadAttachmentAsync
rescocrm edited this page May 15, 2023
·
9 revisions
[v9.1] Initiates the attachment download for specified entity.
Function sends an asynchronous request to application, which downloads the document body (e.g. the annotation) from server and resolves pending Javascript promise.
Argument | Type | Description |
---|---|---|
entityName | String | The logical name of the entity, in most cases "annotation". |
id | String | GUID of the existing entity or null for new one. |
This example demonstrate how to download the note attachment image and set it into <img> element.
// WARNING: async/await pattern requires ECMAScript 6 and it's not supported on Internet Explorer.
// It's supported by all modern browsers including mobile version of Chrome and Safari (requires Android 5+ and iOS 10+).
function downloadNoteAttachment(noteId) {
return __awaiter(this, void 0, void 0, function* () {
try {
var base64str = yield MobileCRM.DynamicEntity.downloadAttachmentAsync("annotation", noteId);
var imgElement = document.getElementById("img-result");
if (imgElement)
imgElement.setAttribute("src", "data:;base64," + base64str); // set the "src" attribute for out <img> element
}
catch (error) {
MobileCRM.bridge.alert("An error occurred: " + error);
}
});
}