Показать сообщение отдельно
Старый 17.10.2008, 12:28   #1  
Казарин Александр is offline
Казарин Александр
Участник
 
58 / 10 (1) +
Регистрация: 17.10.2008
Адрес: Сыктывкар
Получение атрибута из другого объекта
Добрый день!

Испробовал множество вариантов, результат один, помогите разобраться, есть код, который на onChange по значению поля берет атрибуты выбраного объекта.

Т.е. Есть код, который на onChange по значению поля берет атрибуты выбраного объекта., т.е. есть некая форма Incident, на ней есть значение типа lookup (contractdetailid), с выбором того или иного объекта - строки контракта (contractdetail). Этот объект имеет атрибут new_incidenttime.

Код на onChange:
Код:
var oTime = crmForm.all.contractdetailid;
if (oTime.DataValue != null && oTime.DataValue[0] != null)
{
    var Srok = GetAttributeValueByEntityId('contractdetail', oTime.DataValue[0].id, 'new_incidenttime');
}
 
function GetAttributeValueByEntityId(entityName, entytiId, attributeName)
{
    var xml = '' + 
    '[?xml version=`1.0` encoding=`utf-8`?]' + '\r\n' + 
    '[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`]' + '\r\n' + 
    ' [soap:Body]' + '\r\n' + 
    ' [entityName xmlns=`http://schemas.microsoft.com/crm/2006/WebServices`]' + entityName + '[/entityName]' + '\r\n' + 
    ' [id xmlns=`http://schemas.microsoft.com/crm/2006/WebServices`]' + entytiId + '[/id]' + '\r\n' + 
    ' [columnSet xmlns=`http://schemas.microsoft.com/crm/2006/WebServices` xmlns:q=`http://schemas.microsoft.com/crm/2006/Query` xsi:type=`q:ColumnSet`]' + '\r\n' + 
    ' [q:Attributes]' + '\r\n' +
    ' [q:Attribute]' + attributeName + '[/q:Attribute]' + '\r\n' +
    ' [/q:Attributes]' + '\r\n' +
    ' [/columnSet]' + '\r\n' + 
    ' [/soap:Body]' + '\r\n' + 
    '[/soap:Envelope]' + 
    '';
    xml = xml.replace(/\[/gi, String.fromCharCode(60));
    xml = xml.replace(/\]/gi, String.fromCharCode(62));
    xml = xml.replace(/\`/gi, String.fromCharCode(34));
    var xmlHttpRequest = new ActiveXObject('Msxml2.XMLHTTP');
    xmlHttpRequest.Open('POST', 'http://crm/Test/mscrmservices/2006/CrmService.asmx', false);
    xmlHttpRequest.setRequestHeader('SOAPAction','http://schemas.microsoft.com/crm/2006/WebServices/Retrieve');
    xmlHttpRequest.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
    xmlHttpRequest.setRequestHeader('Content-Length', xml.length);
    xmlHttpRequest.send(xml);
    var doc = xmlHttpRequest.responseXML;
    var retValue = '';
    if (doc.selectSingleNode('//RetrieveResult/' + attributeName) != null) retValue = doc.selectSingleNode('//RetrieveResult/' + attributeName).text;
    return retValue;
}
Но в итоге xmlHttpRequest.responseXML получает XML-ошибку в виде:
Код:
...
<faultstring>Server was unable to process request.</faultstring>
<detail>
<error>
<code>0x80040203</code>
<description>Url does not contain MSCRMServices</description>
<type>Platform</type>
</error>
</detail>
...
Ошибка мне не понятная, толи что то с самом коде не верно написал, толи библиотек нет каких то, или на сервере доступ закрыт..