Показать сообщение отдельно
Старый 29.10.2009, 23:00   #2  
Павел Гончаров is offline
Павел Гончаров
Участник
 
6 / 18 (1) ++
Регистрация: 29.10.2009
Адрес: Москва
Доброго времени суток!

Если нужно получить значение поля из связанной записи с помощью JScript, то поможет функция:

/* Получение атрибута * /
/* getAttributeValueFromID(objecttypename,guid,fieldname)); */
/* objecttypename - имя сущности, guid - идентификатор, fieldname - имя поля */

getAttributeValueFromID = function(sEntityName, GUID, sAttributeName)
{
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\">",
GenerateAuthenticationHeader(),
"<soap:Body>",
"<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>",
"<entityName>",
sEntityName,
"</entityName>",
"<id>",
GUID,
"</id>",
"<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>",
"<q1:Attributes>",
"<q1:Attribute>",
sAttributeName,
"</q1:Attribute>",
"</q1:Attributes>",
"</columnSet>",
"</Retrieve>",
"</soap:Body>",
"</soap:Envelope>"
].join("");
var resultXml = executeSoapRequest("Retrieve",xml)
var errorCount = resultXml.selectNodes('//error').length;
var resultnode = resultXml.selectSingleNode("//q1:" + sAttributeName)
var result=null;
if (resultnode!=null) result = resultnode.nodeTypedValue;

if (errorCount != 0)
{
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
result = " ";
alert(msg);
}
else
{
return result;
}
}