Saturday, February 23, 2013

MSCRM 2011: Checking the State of a Form


Sometimes you find it is necessary to do certain functionality in CRM depending on whether you are creating a new record, modifying a record etc. The below is the java script to check the state of the form. Necessary coding can then be entered depending on the state of the form. Hope this comes in handy!  

function getFormType ()  {
 
 var FORM_TYPE_CREATE = 1;

 var FORM_TYPE_UPDATE = 2;

 var FORM_TYPE_READ_ONLY = 3;

 var FORM_TYPE_DISABLED = 4;

 var FORM_TYPE_QUICK_CREATE = 5;

 var FORM_TYPE_BULK_EDIT = 6;
 
 var formType = Xrm.Page.ui.getFormType();

 if (formType == FORM_TYPE_CREATE) {

 alert ("This record has not yet been created.");

 }

 else {

 alert ("This record exists in the database.");

 }

}