Solved

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

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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