How To : Set A Fields On A Form Required Or Recommended Using Java Script in CRM

// Required

Xrm.Page.getAttribute("FieldSchemaName").setRequiredLevel("required");

//Recommended

Xrm.Page.getAttribute("FieldSchemaName").setRequiredLevel("recommended");

// None

Xrm.Page.getAttribute("FieldSchemaName").setRequiredLevel("none");

MS CRM - What is the "IsDirty" Method ?

Hi,

The "IsDirty()" Method returns a Boolean value indicating if there are unsaved changes to  attributes values.

Code:

//To Check if the entity is dirty
var ismodified=Xrm.Page.data.entity.getIsDirty();

//To Get Dirty Fields
var attributes = Xrm.Page.data.entity.attributes.get() ;
for (var i in attributes)
{
var attribute = attributes[i];
if (attribute.getIsDirty())
alert("attribute dirty: " + attribute.getName());
}

Hide and Show Section Using Java Script in CRM

In this article , I am going to explain how to hide sections

Hiding Section

-Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex).setVisible(false);
-Xrm.Page.ui.tabs.get(tabIndex).sections.get("sectionName").setVisible(false);

Showing Section

-Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex).setVisible(true);
-Xrm.Page.ui.tabs.get(tabIndex).sections.get("sectionName").setVisible(true);

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);