CRM 2011 – Javascript to update variables only on Create

[tweetmeme source=”BenHosk” only_single=false]

I had an interesting problem, I wanted to default a drop downlist on an onload event but only if the user was creating a new contact.

The reason I wanted it only for a create is because it would overwrite the value of the variable if I had it on the onload event of the contact because my drop down list had two values and no unassigned value.

http://msdn.microsoft.com/en-us/library/0375b206-d2bf-4034-a41d-fb476ecb4438#BKMK_getFormType

getFormType

Indicates the form context for the record.

Xrm.Page.ui.getFormType()
Return Value
Type: Number
The following table lists the form types that correspond to the return value.
Value Form Type
0 Undefined
1 Create
2 Update
3 Read Only
4 Disabled
5 Quick Create (Deprecated)
6 Bulk Edit

Example: The SDK.UISamples.getFormType alerts the user with a different message depending on the current form type.

getFormType: function () {

 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.");
 }
},

One thought on “CRM 2011 – Javascript to update variables only on Create

  1. BeginnerAtCRM April 18, 2012 / 9:07 pm

    I need to do something similar but in my case I need to copy the GUID of the Contact, which doesn’t exist until the new entity record is saved, I believe. Any ideas? Thanks.

    Like

Leave a Reply

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