Answered by:
How to check if Appointment is New

Question
-
I want to run some code on the onload event of an appointment, but I only want it to do it on NEW appointments. If the user is opening an appointment that is already scheduled then I don't want to run the code.
Is there a value I can check? For example, does a new appointment (one not saved yet) not have and activityid, or statecode? Is there something already built in to CRM like if crmForm.all.isnew = true?
Just to make sure I was looking at the right data and starting small, I tried the below which was followed by an alert only (no other code)
if(crmForm.all.activityid.DataValue == null)
if(typeof(crmForm.all.activityid) == undefined)
and various combinations of the above and with using statecode. All either throws an error and does nothing (no alert).
Thanks in advance!
JP
Friday, April 13, 2012 2:25 PM
Answers
-
Hi,
You need something like:
if (crmForm.FormType == 1) { // TODO: }
hth,
Scott
Scott Durow
Read my blog: www.develop1.net/public
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"- Marked as answer by lifeIsPunny Friday, April 13, 2012 2:47 PM
Friday, April 13, 2012 2:44 PMAnswerer -
Sorry, it was for CRM 2011, but it for CRM4:
if(crmForm.FormType == 1) { // new } else { // not new }
- Marked as answer by lifeIsPunny Friday, April 13, 2012 2:47 PM
Friday, April 13, 2012 2:47 PM
All replies
-
Hi,
Use it:
var formType = Xrm.Page.ui.getFormType(); if (formType == FORM_TYPE_CREATE) { alert("New"); } else { alert("Not new"); }
Friday, April 13, 2012 2:30 PM -
Thanks for the reply - I get an error that it doesn't know what Xrm is. Maybe I should have stated I'm using CRM 4? I changed the code to crmForm.all.getFormType() and it tells me it's an unsupported method.
Any other thoughts?
Friday, April 13, 2012 2:40 PM -
Hi,
You need something like:
if (crmForm.FormType == 1) { // TODO: }
hth,
Scott
Scott Durow
Read my blog: www.develop1.net/public
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"- Marked as answer by lifeIsPunny Friday, April 13, 2012 2:47 PM
Friday, April 13, 2012 2:44 PMAnswerer -
Sorry, it was for CRM 2011, but it for CRM4:
if(crmForm.FormType == 1) { // new } else { // not new }
- Marked as answer by lifeIsPunny Friday, April 13, 2012 2:47 PM
Friday, April 13, 2012 2:47 PM -
That works GREAT!!!! Thanks!!
For my knowledge - what are the other form types and is 1 specifically new?
Thanks again!
Friday, April 13, 2012 2:49 PM -
You can define a set of constants like:
var FormTypes = { Create : 1, Update : 2, ReadOnly : 3, Disabled : 4, QuickCreate : 5, BulkEdit : 6 } if (crmForm.FormType == FormTypes.Create) { // TODO }
hth,
Scott
Scott Durow
Read my blog: www.develop1.net/public
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"Friday, April 13, 2012 3:09 PMAnswerer