Solved

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

Posted on 2012-04-07
5
524 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Sep 22nd 2014 Microsoft released Update Rollup 1 for Microsoft Dynamics CRM 2013 Service Pack 1 and back in July Update Rollup 3 was released.  So we now have:   Update Rollup 1Update Rollup 2Update Rollup 3Service Pack 1Update Rollup 1 for S…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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