Показать сообщение отдельно
Старый 03.06.2009, 10:17   #1  
Murzin Andrey is offline
Murzin Andrey
Участник
 
12 / 10 (1) +
Регистрация: 03.06.2009
Адрес: Россия
Использование веб сервисов.
Здравствуйте, уважаемые.
Сразу скажу, что только начинаю разбираться с CRM 4.0 и могу написать что-нибудь не то, но всё же (читаю SDK).
Проблема такая - в форме Интерес добавлено поле типа lookup (выбирается бизнес-партнер), нужно вычитать Название этой организации, Телефон и вставить в соответствующие поля в форме Интерес.
Насколько я понял по форумам делается это с помощью вэб сервисов.
Пытаюсь сделать, результат следующий: название ставится, телефон нет.
Вопрос как вставить телефон.

Вот что я делаю: на событие OnChange поля customerid (добавленный lookup) вешаю такой код:

var lookupItem = new Array;

lookupItem = crmForm.all.customerid.DataValue;
if (lookupItem[0] != null)
{
alert(crmForm.all.companyname.DataValue = lookupItem[0].name);
alert(lookupItem[0].id);
}

var accountid = "lookupItem[0].id";
var authenticationHeader = GenerateAuthenticationHeader();

// Prepare the SOAP message.
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>account</entityName>"+
"<id>"+accountid+"</id>"+
"<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+
"<q1:Attributes>"+
"<q1:Attribute>telephone1</q1:Attribute>"+
"</q1:Attributes>"+
"</columnSet>"+
"</Retrieve>"+
"</soap:Body>"+
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;

// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
}
// Display the retrieved value.
else
{
alert(resultXml.selectSingleNode("//q1:telephone1").nodeTypedValue);

crmForm.all.telephone1.DataValue = alert(lookupItem[0].telephone1);
}