...colourful technology...

Javascript for CRM 4.0

Client side scripting using Javascript can extend CRM 4 to cater for many weird and wonderful business logic issues.

One of the advantages of using Javascript (over a plugin for instance) is that things happen "immediately" - and so the updating of a field on the form can be seen to cause knock-on effects.  An example of this would be updating a surname and firstname field when a contact is selected.

Useful code snippets

  • Reading the value of an attribute for a given entity - so allows the lookup of data from an associated record
  • Finding the Guid of an attribute (a lookup, so the DataValue contains an array with .id and .name):
    var cty = new Array;
    cty = crmForm.all.new_countyid.DataValue;
    if (cty != null)
    {   // found field
    var ctyid = cty[0].id;
        if (ctyid != null)
        {   // found GUID
  • Retrieving multiple items from multiple records - this Javascript is part of a prototype for attaching sales literature to emails - it works but there are drawbacks...

Some hard-learnt rules

  1. It's a pain to have to edit Javascript inside CRM - so don't - use something better.  Save into a file and copy/paste into the OnLoad event.
  2. Don't attach events to individual fields; put them all in #1 and declare them like this: crmForm.all.new_country.attachEvent("onchange", CountryChanged);
  3. Save event can be cancelled using event.returnValue = false; (easy when you know!)



  • Visual Basic
  • C, C++, C#
  • WinForms
  • SQL
  • CRM 4.0