Skip to content

MobileCRM.DynamicEntity.saveDocumentBodyAsync

maros316 edited this page Feb 17, 2020 · 9 revisions

Arguments

Argument Type Description
entityId String GUID of the existing entity or "null" for new one.
entityName String The logical name of the entity; optional, default is "annotation".
relationship MobileCRM.Relationship The relationship with parent object.
filePath String Absolute or app data-relative path to the file holding the body.
mimeType String MimeType of the content, optional.

This example demonstrates how to save the document body (e.g. attached image) for newly created annotation (Note). Following function locally stores the attachment (defined by file path) for newly created note.

// 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 saveAnnotation(filePath, accountReference) {
	return __awaiter(this, void 0, void 0, function* () {
		///<param name='filePath' type='String'>path to file for annotation attachment.</param>
		///<param name='accountReference' type='MobileCRM.Reference'>Reference to account.</param>
		try {
			var relationship = new MobileCRM.Relationship("objectid", accountReference);
			var annotation = yield MobileCRM.DynamicEntity.saveDocumentBody(null, null, relationship, filePath, null);
			MobileCRM.bridge.alert(annotation.entityName + " '" + annotation.primaryName + "' successfully saved.");
		}
		catch (error) {
			MobileCRM.bridge.alert("An error occurred: " + error);
		}
	});
}
Clone this wiki locally