Knowledge found and lost while working with Microsoft Dynamics CRM
RSS icon Home icon
  • Verifying Form Context Before Invoking JavaScript Code

    Posted on March 19th, 2007 Mitch Milam Print Print 1 comment

    I was testing a callout-based solution for customer this afternoon when I ran into something very interesting when adding a new Contact ( to the Primary Contact Attribute of the Account ), using the Quick Create feature.

    Quick Create Backgrounder

    If you've never noticed, several CRM Lookup dialogs have a New button that allow you to create new records on the fly without having to change your context to that particular record type and selecting the New button.  CRM will display a dialog that contains all of the Business Required and Business Recommended Attributes for you to complete, as shown below:

     

     

    The Problem I Found

    It turns out that since this is my main development server, I have all types of strange configurations loaded, including something that uses the OriginatingLeadID attribute in the Form OnLoad event.  Unfortunately, since the OriginatingLeadID is not a Required or Recommended Attribute, it was not displayed on the Quick Create Form and therefore unavailable to the OnLoad event.  This produced the following Error:

     

    Ensuring a Smooth User Experience

    The easiest method for ensuring your OnLoad JavaScript functions as expected, is to verify the CRM Form Type using code similar to the following:

     

    // Perform this work only on Create
    if (crmForm.FormType == 1)
    {
      // do the work here
    }
    

     

    CRM Defines the following form types:

    Undefined Form Type = 0

    Create Form = 1

    Update Form = 2

    Read Only Form = 3

    Disabled Form = 4

    Quick Create Form = 5

    Bulk Edit Form = 6

     

    For more information on FormTypes and other CRM Form Properties, visit this link.

    Customization, Dynamics CRM
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    4,215 views

    Leave a reply