How To : Get All Required Fields Using Java Script In CRM

Introduction :  Suppose you would like to get all the required fields on a form using java script.

Code:

var message = "The following fields are required:\n";
Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {
if (attribute.getRequiredLevel() == "required")
{
message += "  \u2219 " + attribute.getName() + "\n";
}});
alert(message);