MobileCRM.UI.EntityList.onSave - Resconet/JSBridge GitHub Wiki

[v10.0] Binds or unbinds the handler for onSave event on EntityList.

Bound handler is called with the EntityList object as an argument. The EntityList context object contains "entities" property with the list of all changed entities and property "errorMessage" that can be used to cancel save with an error.

Arguments

Argument Type Description
handler function(entityList) The handler function that has to be bound or unbound.
bind Boolean Determines whether to bind or unbind the handler.
scope Object The scope for handler calls.

This example demonstrates how to validate and modify changed entities before saving.

MobileCRM.UI.EntityList.onSave(function (entityList) {
	return __awaiter(this, void 0, void 0, function* () {
		const context = entityList.context;
		const changedEntities = context.entities;
		const saveHandler = entityList.suspendSave();
		try {
			// Validate changes and return the list of entities that must be changed before saving
			const entitiesToModify = yield GetEntitiesToChange(changedEntities);
			MobileCRM.UI.EntityList.requestEditedEntities(editedEntities => {
				for (const entityToModify of entitiesToModify) {
					const toChange = editedEntities.find(e => e.id == entityToModify.id);
					toChange.properties.anyfield = entitiesToModify.anyfield; // Perform any SYNCHRONOUS modification here
				}
				saveHandler.resumeSave();
			});
		}
		catch (e) {
			saveHandler.resumeSave(e.message);
		}
	});
}, true);