Tuesday, June 11, 2013

CRM 2011 - Form Type using JavaScript

In our real life scenarios we have several occasion where we have to identify the state of the action on the page, whether its a Creation of a record, updating a record and so on. In such case, using java Script we can identify the state and do our next step accordingly.

Xrm.Page.ui contains different methods to retrieve information about the user interfaces and its sub components in the form. Within that scope we have a method using which we can achieve this requirement.

Xrm.Page.ui.getFormType()

This method indicates the form context for the record. Indication of the form type is through an integer value from which we can identify the state of the record. Below are the list of possible numbers which can be returned via this method.

  • 0 - Undefined
  • 1 - Create
  • 2 - Update
  • 3 - Read Only
  • 4 - Disabled
  • 5 - Quick Create (Deprecated but still the same is supported)
  • 6 - Bulk Edit
  • 11 - Read optimized
Example:

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

switch (formType)



{
 
case 0: //Logic for undefined.

break;

case 1: //Logic for Create.

break;

case 2: //Logic for Update.

break;

case 3: //Logic for Read Only.

break;

case 4: //Logic for Disabled.

break;

case 5: //Logic for Quick Create.

break;

case 6: //Logic for Bulk Edit.

break;

case 11: //Logic for Read optimized.

break;


}

No comments:

Configuration for CRM Plugins

CRM plugins are always great feature where we can automate many functionality which we cannot automate from user interface. But almost eve...