Stefan Pienaar
I would love to change the world, but they won't give me the source code

Creating a CRM Javascript function which is accessable to all events on a form

June 26, 2009 11:56 by StefanPienaar

There might be situations where you’ll need to perform the same actions/calculations (via javascript) on different form events. Code duplication is always a bad idea so you could either include an external javascript file with your function or create the function in your form’s load event as follows:

CalculateAge = function()
{
  if(crmForm.all.new_dateofbirth.DataValue != null)
  {
     // Your javascript logic
  }
}

You can then call this function from any event on the same form. For example I could call this function right after creating it on the load event to ensure the age is always updated when the record is opened, and I can also call it from my date of birth field’s change event. To call the event, I would use this line:
 
CalculateAge();

Categories: Microsoft CRM 4
Actions: E-mail | Permalink | Comments (2)

Comments