Sunday, September 7, 2008

Microsoft Dynamics CRM Javascript Access to Form Elements

Here's how to access each control on your forms using Javascript. Using this information you can add very useful functionality to CRM's front end.

There are a couple of ways to do this, you can choose which ever suits your situation best...

Currently displayed entitie's GUID:

To access a control on the form:
    // OR

Hide/show attribute(set to visible or invisible):
    //Hide it
    crmForm.all.[attributename].style.display = "none";
    //Show it
    crmForm.all.[attributename].style.display = "inline";

Enable/disable attribute:
   crmForm.all.[attributename].Disabled = true;
   crmForm.all.[attributename].Disabled = false;

Does control/attribute contain any data?
   if (crmForm.all.[attributename] != null)
       //Contains some data

Control's value(this is the current on screen value. ie, may not have been saved yet):
   // OR
   // OR if its a checkbox
   crmForm.all.[attributename].Checked = [true false=""]
   // OR if its a lookup
     //Descriptive name for the selected item
     //GUID value of the selected item
     //Type of entity selected in the lookup(1=Account, 2=Contact...)
     //Descriptive name for the selected entity type

1 comment:

Pranay said...

Thanks for a usefull post. I have a query here,
lets say i have added an "OnChange" event for a form field and basing on some logic in that jscript i would want to retain the old value of the field.
ex: lets say the value si 10 and i updated it to 20, and i want to populate it back to 10.

How can i do this?