Skip to content

MobileCRM.UI.EntityForm.suspendSave

rescocrm edited this page May 15, 2023 · 9 revisions

Suspends current "onSave" validation and allows performing another asynchronous tasks to determine the validation result

This example demonstrates how to perform the asynchronous validation in "onSave" handler. This code suspends the validation and fetches the list of associated contacts. Then it resumes the validation and shows an error if no Contact is associated with currently edited Account.

MobileCRM.UI.EntityForm.onSave(onSaveValidation, true, null);
function onSaveValidation(entityForm) {
	/// <param name="entityForm" type="MobileCRM.UI.EntityForm"/>
	var editedAccount = entityForm.entity;
	var saveHandler = entityForm.suspendSave();
	var fetchEntity = new MobileCRM.FetchXml.Entity("contact");
	fetchEntity.addAttribute("contactid");
	var filter = new MobileCRM.FetchXml.Filter();
	filter.where("parentcustomerid", "eq", editedAccount.id);
	fetchEntity.filter = filter;
	var fetch = new MobileCRM.FetchXml.Fetch(fetchEntity);
	fetch.execute(null, // Take the results as an array of arrays with field values
	function (result) {
		/// <param name="result" type="Array"/>
		if (result && result.length)
			saveHandler.resumeSave();
		else
			saveHandler.resumeSave("At least one contact is required");
	}, function (error) {
		saveHandler.resumeSave("Contact fetch error: " + error);
	});
}
Clone this wiki locally