Показать сообщение отдельно
Старый 03.06.2009, 14:30   #1  
a33ik is offline
a33ik
Чайный пьяница
Аватар для a33ik
MCP
MCBMSS
Злыдни
Соотечественники
Most Valuable Professional
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии AXAWARD 2013
Лучший по профессии 2011
Лучший по профессии 2009
 
3,243 / 896 (36) +++++++
Регистрация: 02.07.2008
Адрес: Greenville, SC
Lightbulb
Цитата:
Сообщение от Murzin Andrey Посмотреть сообщение
Код следующий:

var lookupItem = new Array;

lookupItem = crmForm.all.customerid.DataValue;

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>"+lookupItem[0].id+"</id>"+
"<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+
"<q1:Attributes>"+
"<q1:Attribute>telephone1</q1:Attribute>"+
"</q1:Attributes>"+

"<q1:Attributes>"+
"<q1:Attribute>name</q1:Attribute>"+
"</q1:Attributes>"+

"<q1:Attributes>"+
"<q1:Attribute>address1_line1</q1:Attribute>"+
"</q1:Attributes>"+

"<q1:Attributes>"+
"<q1:Attribute>address1_city</q1:Attribute>"+
"</q1:Attributes>"+

"<q1:Attributes>"+
"<q1:Attribute>revenue</q1:Attribute>"+
"</q1:Attributes>"+

"<q1:Attributes>"+
"<q1:Attribute>numberofemployees</q1:Attribute>"+
"</q1:Attributes>"+

"<q1:Attributes>"+
"<q1:Attribute>industrycode</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
{
if (crmForm.all.customerid.DataValue != null && crmForm.all.customerid.DataValue[0] != null)
{
resultXml.selectSingleNode("//q1:telephone1").nodeTypedValue;
resultXml.selectSingleNode("//q1:name").nodeTypedValue;
resultXml.selectSingleNode("//q1:address1_line1").nodeTypedValue;
resultXml.selectSingleNode("//q1:address1_city").nodeTypedValue;
resultXml.selectSingleNode("//q1:revenue").nodeTypedValue
resultXml.selectSingleNode("//q1:numberofemployees").nodeTypedValue;
resultXml.selectSingleNode("//q1:industrycode").nodeTypedValue;

crmForm.all.telephone1.DataValue = resultXml.selectSingleNode("//q1:telephone1").nodeTypedValue;

crmForm.all.companyname.DataValue = resultXml.selectSingleNode("//q1:name").nodeTypedValue;

crmForm.all.address1_line1.DataValue = resultXml.selectSingleNode("//q1:address1_line1").nodeTypedValue;

crmForm.all.address1_city.DataValue = resultXml.selectSingleNode("//q1:address1_city").nodeTypedValue;

crmForm.all.revenue.DataValue = resultXml.selectSingleNode("//q1:revenue").nodeTypedValue;

crmForm.all.numberofemployees.DataValue = resultXml.selectSingleNode("//q1:numberofemployees").nodeTypedValue;

crmForm.all.industrycode.DataValue = resultXml.selectSingleNode("//q1:industrycode").nodeTypedValue;
}
}
Сам не тестировал, но попробуйте так:

Код:
if (crmForm.all.customerid.DataValue != null && crmForm.all.customerid.DataValue[0] != null)
{
var lookupItem = new Array;

lookupItem = crmForm.all.customerid.DataValue;

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>"+lookupItem[0].id+"</id>"+
"<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+
"<q1:Attributes>"+
"<q1:Attribute>telephone1</q1:Attribute>"+
"</q1:Attributes>"+

"<q1:Attributes>"+
"<q1:Attribute>name</q1:Attribute>"+
"</q1:Attributes>"+

"<q1:Attributes>"+
"<q1:Attribute>address1_line1</q1:Attribute>"+
"</q1:Attributes>"+

"<q1:Attributes>"+
"<q1:Attribute>address1_city</q1:Attribute>"+
"</q1:Attributes>"+

"<q1:Attributes>"+
"<q1:Attribute>revenue</q1:Attribute>"+
"</q1:Attributes>"+

"<q1:Attributes>"+
"<q1:Attribute>numberofemployees</q1:Attribute>"+
"</q1:Attributes>"+

"<q1:Attributes>"+
"<q1:Attribute>industrycode</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
{
crmForm.all.telephone1.DataValue = resultXml.selectSingleNode("//q1:telephone1") == null ? "" : resultXml.selectSingleNode("//q1:telephone1").nodeTypedValue;

crmForm.all.companyname.DataValue = resultXml.selectSingleNode("//q1:name") == null ? "" : resultXml.selectSingleNode("//q1:name").nodeTypedValue;

crmForm.all.address1_line1.DataValue = resultXml.selectSingleNode("//q1:address1_line1") == null ? "" : resultXml.selectSingleNode("//q1:address1_line1").nodeTypedValue;

crmForm.all.address1_city.DataValue = resultXml.selectSingleNode("//q1:address1_city") = null ? "" : resultXml.selectSingleNode("//q1:address1_city").nodeTypedValue;

crmForm.all.revenue.DataValue = resultXml.selectSingleNode("//q1:revenue") == null ? "" : resultXml.selectSingleNode("//q1:revenue").nodeTypedValue;

crmForm.all.numberofemployees.DataValue = resultXml.selectSingleNode("//q1:numberofemployees") == null ? "" : resultXml.selectSingleNode("//q1:numberofemployees").nodeTypedValue;

crmForm.all.industrycode.DataValue = resultXml.selectSingleNode("//q1:industrycode") == null ? "" : resultXml.selectSingleNode("//q1:industrycode").nodeTypedValue;

}
}
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством.

Подписывайтесь на мой блог, twitter и YouTube канал.
Пользуйтесь моим Ultimate Workflow Toolkit