Solved

CRM 2011 - How do I use Java Script  to detect the record status

Posted on 2012-04-07
5
516 Views
Last Modified: 2012-04-08
I would like to hook a Javascript function on the OnLoad event of the form so that the function will hide the subgrid if this is a new record.

How can I tell if the form is  open because the 'Add New' button is click.
0
Comment
Question by:tommym121
  • 3
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 500 total points
ID: 37820779
Hi tommym121,

Use Xrm.Page.ui.getFormType() to determine if this is a new record or not.

http://msdn.microsoft.com/en-us/library/gg327828.aspx#BKMK_getFormType


Regards,
Chinmay.
0
 

Author Comment

by:tommym121
ID: 37821021
Thanks.
0
 

Author Comment

by:tommym121
ID: 37821066
Chinmay.

In MSDN, it has the following,  I am not sure I understand the syntax. Do you mind explaining it for me thanks.

getFromType:function() {
},


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

Expert Comment

by:Chinmay Patel
ID: 37821117
Hi tommym121,

Sure.

// This how you will call the function
getFromType:function() {
},

// This is function body
getFormType: function () {

// They have defined constants so that you don't have to remember the value of FormType, instead of 1 you can use FORM_TYPE_CREATE in the code where you use Form Type
 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;

// This is where they get the form type from Xrm.Page
 var formType = Xrm.Page.ui.getFormType();

// This is how you will use the constants that you created earlier
 if (formType == FORM_TYPE_CREATE) {
  alert("This record has not yet been created.");
 }
 else {
  alert("This record exists in the database.");
 }

// Basically rather than showing an alert based on the form type you will take a particular action
// Possible use for you is 

 if (formType == FORM_TYPE_CREATE) {
  HideSubGrid();
 }
 

Open in new window



Regards,
Chinmay.
0
 

Author Closing Comment

by:tommym121
ID: 37821731
Thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This is a walkthrough guide I wrote whilst upgrading my on-premise MS Dynamics CRM 3.0 deployment to 4.0. This covers the actual installation of the product to a working level for my system, I ran into a lot of issues that the steps below fixed so h…
Automatically creating a Trello card using data from a Microsoft Dynamics CRM record turned out to be an easy project that yielded great results.  Here's how I did this for an internal team at General Code.
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now