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

java script and Auto format Telephone and Fax number in CRM 2011

$
0
0

Hi Guys,

I am currently trying to auto format my Main telephone + and Fax number in the CRM 2011. My problem here is that I am unable to automate the "Fax" number. But the Main telephone number is able to be autoformated based on the code i have provided below.

I am pretty new to java scripting, so i don't know where i'm making the mistake. The codes for both functions are essentially the same with the exception of variable names  being changed to their respectable field.

I would greatly appreciate if anyone can solve my problem or identify the issue with my code.

Thanks in advance!

function dsl_FormatPhone()// Function for main Telephone
{
var InputPhone = Xrm.Page.getAttribute( "telephone1" ).getValue();
  if( InputPhone != null)
   {
    var regexObj = /^(?:\+?1[-. ]?)?(?:\(?([0-9]{3})\)?[-. ]?)?([0-9]{3})[-. ]?([0-9]{4})$/;
    if (regexObj.test(InputPhone))
    {
    var parts = InputPhone.match(regexObj);
    var phone = "";
     if (parts[1]) 
        {
        phone += " (" + parts[1] + ") "; 
     //       phone +=  + parts[1] + "-"; 
         }
    phone += parts[2] + "-" + parts[3];
    //alert("Phone # is " + phone);
    Xrm.Page.getAttribute("telephone1").setValue(phone);
   }
  }
}

function dsl_FormatPhone2() //function for fax numbers
{
var InputPhone2 = Xrm.Page.getAttribute( "fax" ).getValue();
  if( InputPhone2 != null)
   {
    var regexObj = /^(?:\+?1[-. ]?)?(?:\(?([0-9]{3})\)?[-. ]?)?([0-9]{3})[-. ]?([0-9]{4})$/;
    if (regexObj.test(InputPhone2))
    {
    var parts = InputPhone2.match(regexObj);
    var phone = "";
     if (parts[1]) 
        {
        phone += " (" + parts[1] + ") "; 
     //       phone +=  + parts[1] + "-"; 
         }
    phone += parts[2] + "-" + parts[3];
    //alert("Phone # is " + phone);
    Xrm.Page.getAttribute("fax").setValue(phone);
   }
  }
}




Viewing all articles
Browse latest Browse all 8223

Trending Articles



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