Solved

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

Posted on 2012-04-07
5
541 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

687 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