Get Form type in CRM 2013 using JavaScript

Hello everyone,

In this article I will talk about how to get form type in crm 2013 using javascript.

Sometimes we need to identify if the current form is a Create Form or Update Form etc. And we might want to write our javascript code considering these types of conditions.

We do this with the following code:

Xrm.Page.ui.getFormType()

For example if we want to check if the current form is a create form. In this conditon we want some code lines to be processed and otherwise if the current form is an update form we want some other code lines to be processed.

Here is how we do this in javascript:

var isCreateForm = (Xrm.Page.ui.getFormType() == 1);
var isUpdateForm = (Xrm.Page.ui.getFormType() == 2);
if (isCreateForm === true) {
    // code to be executed if the current form is a Create Form
} else if (isUpdateForm === true) { < /pre>
    // code to be executed if the current form is an Update Form
}

We can also write the code above in a function to be called on load event to identify Form type and execute the code we want for each condition.

function enableOrDisableFields() {
    var isCreateForm = (Xrm.Page.ui.getFormType() == 1);
    var isUpdateForm = (Xrm.Page.ui.getFormType() == 2);
    if (isCreateForm === true) {
        // code to be executed if the current form is a Create Form
    } else if (isUpdateForm === true) {
        // code to be executed if the current form is an Update Form
    }
}

Following table consists of the values of Form types in CRM:

Form Type Value
Undefined 0
Create 1
Update 2
Read Only 3
Disabled 4
Quick Create (Deprecated) 5
Bulk Edit 6
Read Optimized (Deprecated) 11

 

I  hope you’ve enjoyed this tutorial.

Happy CRMin’ 🙂

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *