Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

CRM 2016 On Premise Event is undefined

$
0
0

After installing CRM 2016; we noticed that when certain fields were changed (example under accounts, telephone1) there was a script error.

One of the scripts for this record has caused an error. For more details, download the log file.
TypeError: Unable to get property 'srcElement' of undefined or null reference at telephone1_onchange (https://systemsource.syssrc.com/%7B636110959730000359%7D/WebResources/Account_main_library.js?ver=-495258446:17:1)

I traced the error down to the onchange event for the field.  This is the standard onchange event (i.e. we have not customized it)

With some judicious use of alert statements, it became obvious the event being passed in is null.

Any thoughts on the cause of this.  The issue was not present with CRM2016.  It happens on both Microsoft Edge and IE.

Our end goal is to look at the area code portion of the telephone number and flag out of area calls, but that cannot happen if we cannot even see the event.

Below is the code for verifying the field.  It is after an upgrade and we have no record of ever having changed the field

function telephone1_onchange()
{
/*
Installation:
Add this script to onChange event of any phone number field.
Description:
This method will auto-format basic 7 and 10 digit US phone numbers,
  while leaving any extensions.
It will also translate any letters in the input to its equivalent phone digit.
Example: (773) 555-1212
*/

// Get the field that fired the event
var oField = event.srcElement;

// Verify that the field is valid
if (typeof(oField) != "undefined" && oField != null)
{

  if (oField.DataValue != null)
  {
    // Remove any special characters
    var sTmp = oField.DataValue.replace(/[^0-9,A-Z,a-z]/g, "");
    // Translate any letters to the equivilant phone number, if method is included
    try
    {
      if (sTmp.length <= 10)
      {
      sTmp = TranslateMask(sTmp);
      }
      else
      {
        sTmp = TranslateMask(sTmp.substr(0,10)) + sTmp.substr(10,sTmp.length);
      }
    }
    catch(e)
    {
    }
    // If the number is a length we expect and support,
    // format the translated number
    switch (sTmp.length)
    {
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 8:
    case 9:
      break;
    case 7:
      oField.DataValue = sTmp.substr(0, 3) + "-" + sTmp.substr(3, 4);
      break;
    case 10:
      oField.DataValue = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4);
      break;
    default:
      oField.DataValue = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4) + " " + sTmp.substr(10,sTmp.length);
      break;
    }
  }
}


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>