Спасибо за помощь
Вот в итоге нашел решение на Onchange event
Код:
if (crmForm.all.to.DataValue != null && crmForm.all.directioncode.DataValue == true)
{
var lookUp = new Array();
lookUp = crmForm.all.to.DataValue;
var pId = lookUp[0].id;
var pType = lookUp[0].typename;
var phoneField = "telephone1";
if (pType == "systemuser")
{
phoneField = "address1_telephone1";
}
var authenticationHeader = GenerateAuthenticationHeader();
// Define the SOAP XML to access Microsoft Dynamics CRM Web service.
var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap="+
"\"http://schemas.xmlsoap.org/soap/envelope/\" "+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
authenticationHeader+
"<soap:Body>" +
"<Retrieve xmlns="+
"\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
"<entityName>" + pType + "</entityName>" +
"<id>" + pId + "</id>" +
"<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'><q1:Attributes><q1:Attribute>" + phoneField + "</q1:Attribute></q1:Attributes></columnSet>" +
"</Retrieve>"+
"</soap:Body>" +
"</soap:Envelope>";
// Create an instance of an XMLHTTP object.
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
// Configure the XMLHttp object for the
// Microsoft CRM Web services.
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
);
// Send the XMLHttp request.
xmlHttpRequest.send(xml);
// Capture the XMLHttp response in XML format.
var resultXml = xmlHttpRequest.responseXML;
var pNum = null;
if (resultXml.selectNodes("//q1:" + phoneField).length == 1)
{
crmForm.all.phonenumber.DataValue = resultXml.selectSingleNode("//q1:" + phoneField).text;
}
}