MobileCRM.DynamicEntity.loadDocumentBodyAsync - Resconet/JSBridge GitHub Wiki

Asynchronously loads the document body for specified entity.

Function sends an asynchronous request to application, where the locally stored document body (e.g. the annotation.documentbody) is encoded to base64 and pending Javascript promise is resolved. This function supports both online data and the data stored in local database/BLOB store.

Arguments

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 demonstrates how to load the document body (e.g. attached image) for given annotation (Note). Following function loads locally stored attachment for note defined by its id and sets the base-64 data as image source.

// 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 loadAccountDocumentBody(accountid) {
	return __awaiter(this, void 0, void 0, function* () {
		try {
			var base64str = yield MobileCRM.DynamicEntity.loadDocumentBody("annotation", accountidid);
			MobileCRM.bridge.alert("Base64String: \n\n" + base64str);
			var imgElement = document.getElementById("img-result");
			if (imgElement)
				imgElement.setAttribute("src", "data:image/jpeg;base64," + base64str); // set the "src" attribute for out <img> element
		}
		catch (error) {
			MobileCRM.bridge.alert("An error occurred: " + error);
		}
	});
}
⚠️ **GitHub.com Fallback** ⚠️