Showing posts with label Phone Number. Show all posts
Showing posts with label Phone Number. Show all posts

Monday, January 31, 2011

CRM 4.0: Phone Call Entity - Populate Phone Number

Use the code below to populate the phone number field on a phone call record from a lead or contact (regarding object). Also, you can populate the memo/description field to contain all available numbers (home, business, and/or mobile).



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Populate Phone Number Field - by LBMC, Josh Yockey//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(crmForm.FormType == 1 && crmForm.all.regardingobjectid.DataValue != null
&& (crmForm.all.regardingobjectid.DataValue[0].typename == "lead" || crmForm.all.regardingobjectid.DataValue[0].typename == "contact"))
{
var xml = "" +
"" +
"" +
GenerateAuthenticationHeader() +" " +
" " +
" crmForm.all.regardingobjectid.DataValue[0].typename" +
" "+ crmForm.all.regardingobjectid.DataValue[0].id + "" +
" " +
" " +
" telephone2" +
" mobilephone" +
" telephone1" +
"
" +
"
" +
"
" +
"
" +
"
" +
"";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseXML;

var home = "";
var mobile = "";
var business = "";
var desc = "";
crmForm.all.phonenumber.DataValue = "";

var node = resultXml.selectSingleNode("//q1:telephone2");
if (node != null)
home = resultXml.selectSingleNode("//q1:telephone2").text;

node = resultXml.selectSingleNode("//q1:mobilephone");
if (node != null)
mobile = resultXml.selectSingleNode("//q1:mobilephone").text;

node = resultXml.selectSingleNode("//q1:telephone1");
if (node != null)
business = resultXml.selectSingleNode("//q1:telephone1").text;

if (home.length > 0)
{
crmForm.all.phonenumber.DataValue = home;
desc += "\nHome: " + home;
}
if (mobile.length > 0)
{
if (crmForm.all.phonenumber.DataValue == null || crmForm.all.phonenumber.DataValue.length == 0)
{
crmForm.all.phonenumber.DataValue = mobile;
}
desc += "\nMobile: " + mobile;
}
if (business.length > 0)
{
if (crmForm.all.phonenumber.DataValue == null || crmForm.all.phonenumber.DataValue.length == 0)
{
crmForm.all.phonenumber.DataValue = business;
}
desc += "\nBusiness: " + business;
}

crmForm.all.description.DataValue = desc;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Thursday, September 2, 2010

CRM Phone Number Formatting onChange with Extensions

Format Phone Numbers in CRM

Format (xxx) xxx-xxxx

var oField = event.srcElement;
if (typeof(oField) != "undefined" && oField != null && oField.DataValue != null)
{
var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
if(sTmp.length == 10)
{
oField.DataValue = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4);
}
else
{
alert('Phone must contain 10 numbers.');
}
}


Format xxx-xxx-xxxx

var oField = event.srcElement;
if (typeof(oField) != "undefined" && oField != null && oField.DataValue != null)
{
var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
if(sTmp.length == 10)
{
oField.DataValue = sTmp.substr(0, 3) + "-" + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4);
}
else
{
alert('Phone must contain 10 numbers.');
}
}


Format xxx.xxx.xxxx

var oField = event.srcElement;
if (typeof(oField) != "undefined" && oField != null && oField.DataValue != null)
{
var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
if (sTmp.length == 10)
{
oField.DataValue = sTmp.substr(0, 3) + "." + sTmp.substr(3, 3) + "." + sTmp.substr(6, 4);
}
else
{
alert('Phone must contain 10 numbers.');
}
}


Other Formatting Issues:
Remove leading digit if number is 1

var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
if (sTmp.substr(0, 1) == "1")
{
sTmp = sTmp.substr(1, sTmp.length-1);
}


Allowing only 7 digits (no area code)

else if (sTmp.length == 7)
{
oField.DataValue = sTmp.substr(0, 3) + "-" + sTmp.substr(3, 4);
}
else
{
alert('Phone must contain 7 or 10 numbers.');
}


Allowing extensions (requires area code)

else if (sTmp.length > 10)
{
oField.DataValue = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4) + " ext: " + sTmp.substr(10, sTmp.length-10);
}
else
{
alert('Invalid phone number. If using an extension, you must enter area code also.');
}