JavaScripts in CRM 2011
// Get the label of the control
Xrm.Page.ui.controls.get('wwb2c_approved').getLabel()
// Get record id
crmForm.ObjectId --> Xrm.Page.data.entity.getId()
// set field as required based value of a check box field.
function OnChangeBoolField()
{
var varBool = Xrm.Page.data.entity.attributes.get("boolFieldName").getValue();
if(varBool == false)
{
Xrm.Page.getAttribute("new_startdate").setRequiredLevel("required");
Xrm.Page.getAttribute("new_dueby").setRequiredLevel("required");
}
else
{
Xrm.Page.getAttribute("new_startdate").setRequiredLevel("none");
Xrm.Page.getAttribute("new_dueby").setRequiredLevel("none");
}
}
// Compare Dates
function ValidateDates()
{
var startdate = Xrm.Page.getAttribute('new_startdate').getValue();
var dueby = Xrm.Page.getAttribute('new_dueby').getValue();
if(startdate != null && dueby != null)
{
if(dueby.setHours(0,0,0,0) < startdate.setHours(0,0,0,0))
{
alert('Due By must be greater than or equal to Start Date');
event.returnValue = false;
return false;
}
}
}
// few more JavaScript code
// function to check for Status Code for Medical pre clearance
function OnSave()
{
if(Xrm.Page.data.entity.getIsDirty())
{
// get the value of Status Code option set
var statusCodeOptionSet = Xrm.Page.getAttribute("statuscode").getSelectedOption().value;
// if selected status code is Medically Pre Cleared i.e. 100000006
if(statusCodeOptionSet == 100000006)
{
// ask for confirmation before saving the record
var response = confirm("sample"+"\n"+"text");
if(!response)
{
event.returnValue = false;
return false;
}
}
}
}
Comments


Been reading your site for a while now and must say; good writing. Usually I don�t make it through an entire writeup but you have wellwritten and interesting points. Looking forward to more from you.
I also need to show hide the save button depending on the user role through javascript.
Hi Nishant, how can we hide the save button in ribbon in crm 2011 using Javascript. Can pls post this. Thanks ..
hey nishant could you plz again upload partial and transitive dependency document…..