Check mandatory fields using JavaScript in CRM

Hello everyone,

In this article I will share a javascript function. With the help of this function you will be able to check if all mandatory fields are populated using JavaScript in CRM.

Check mandatory fields using JavaScript in 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() {
    var populated = true;

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

    return populated;
}

Hope this helps!

See you 🙂

Leave a Reply

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