Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-04-07
5
Medium Priority
?
557 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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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…
Desired Skill Set for Microsoft Dynamics CRM Technical Resources – Part I
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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