Check mandatory fields using JavaScript in Dynamics CE/CRM

Check mandatory fields using JavaScript in CE/CRM

This function returns false if there is at least one field is not populated on the form.

Here is the function:

//Checks if all the mandatory fields are populated.
function CheckMandatoryFields(executionContext) {
	formContext = executionContext.getFormContext();  
	var populated = true;
	formContext.getAttribute(function (attribute, index) {
		if (attribute.getRequiredLevel() == "required") {
			if(attribute.getValue() === null) {
				populated = false;
			}
		}
	});
	return populated;
}

Work Cited:
Original script taken and modified from http://mehmetgunen.com/check-mandatory-fields-using-javascript-in-crm/

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.