locked
Phone formatting no longer works after UR 12 RRS feed

  • Question

  • After installing UR 12 there are a number of jscript web resources that no longer function.  One in particular is phone formatting because it contains srcElement.  While MS provided a code validation tool and list of items like srcElement that would cause problems, I've not seen any reference source on what to use in its place.  If you can direct me to a resource it would be helpful.  Here is our current code:

    function phonefield_onchange()
    {
    // Get the field that fired the event.
    var oField = event.srcElement;
    // Validate the field information.
    if (oField.getValue() != 'undefined' && oField.getValue() != null)
       {
    // Remove any nonnumeric characters.
     var sTmp = oField.getValue().replace(/[^0-9]/g, '');
    // If the number has a valid length, format the number.
     switch (sTmp.length)
        {
       case '4105551212'.length:
         oField.setValue('(' + sTmp.substr(0, 3) + ') ' + sTmp.substr(3, 3) + '-' + sTmp.substr(6, 4));
         break;
       case '5551212'.length:
         oField.setValue(sTmp.substr(0, 3) + '-' + sTmp.substr(3, 4));
         break;
       }
       }
    }


    Ken Compter

    Wednesday, June 5, 2013 4:40 PM

Answers

  • In this case you can add a parameter to the function like

    function phonefield_onchange(field)
    {
    // Get the field that fired the event.
    var oField = Xrm.Page.getAttribute(field);
    // rest of the function ...

    and specify the field name as parameter when you attach the event


    My blog: www.crmanswers.net

    • Proposed as answer by Guido PreiteMVP Wednesday, June 5, 2013 5:00 PM
    • Marked as answer by kcompter Wednesday, June 5, 2013 6:05 PM
    Wednesday, June 5, 2013 5:00 PM

All replies

  • just change the first line with this:

    var oField = Xrm.Page.getAttribute("fieldname");

    where fieldname is the name of your field.


    My blog: www.crmanswers.net

    Wednesday, June 5, 2013 4:43 PM
  • Thanks for your reply.  I am trying to use a web resource that I can use on any phone field on any entity.  Using specific field name means a web resource for each phone field.  Any other ideas?


    Ken Compter

    Wednesday, June 5, 2013 4:47 PM
  • In this case you can add a parameter to the function like

    function phonefield_onchange(field)
    {
    // Get the field that fired the event.
    var oField = Xrm.Page.getAttribute(field);
    // rest of the function ...

    and specify the field name as parameter when you attach the event


    My blog: www.crmanswers.net

    • Proposed as answer by Guido PreiteMVP Wednesday, June 5, 2013 5:00 PM
    • Marked as answer by kcompter Wednesday, June 5, 2013 6:05 PM
    Wednesday, June 5, 2013 5:00 PM
  • That worked!  Thanks so much for the help.

    Ken Compter

    Wednesday, June 5, 2013 6:05 PM