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

4 thoughts on “JavaScripts in CRM 2011”

  1. 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.

    Like

Share your thoughts

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