CRM 2013 Check if all mandatory fields are populated with JavaScript

Today I needed to check if all fields on a given form were populated, as I didn’t know exactly which fields would be mandatory at any one time I need something that dynamically searched the form for all mandatory fields and checked to see if they had a value.

Fortunately this is actually pretty straight forward.

/**
Checks if all the mandatory fields are populated.

@method MandatoryPopulated
@return {bool} True if all fields are populated
**/
MandatoryPopulated: function() {
	populated = true;

	Xrm.Page.getAttribute(function (attribute, index) {
		if (attribute.getRequiredLevel() == "required") {
			if(attribute.getValue() === null) {
				populated = false;
			}
		}
	});
	
	return populated;
},
Advertisements

One thought on “CRM 2013 Check if all mandatory fields are populated with JavaScript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s