2013-07-31 2 views
0

Я хотел бы заполнить описание случая CRM описанием выбранного объекта (описание случая будет отключено до тех пор, пока объект не будет выбран). Я буду использовать его для автоматического заполнения некоторых вопросов на основе темы. Как получить описание объекта? я могу получить идентификатор и имя субъекта, но не могу найти что-либо в Интернете, которое проходит через больше атрибутов, чем те 2.Получить атрибут значения поиска - javascript/CRM 2011

Спасибо большое!

Laurent

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>" + 
" <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
" <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + 
" <q1:EntityName>subject</q1:EntityName>" + 
" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
" <q1:Attributes>" + 
" <q1:Attribute>description</q1:Attribute>" + 
" </q1:Attributes>" + 
" </q1:ColumnSet>" + 
" <q1:Distinct>false</q1:Distinct>" + 
" <q1:Criteria>" + 
" <q1:FilterOperator>And</q1:FilterOperator>" + 
" <q1:Conditions>" + 
" <q1:Condition>" + 
" <q1:AttributeName>subjectid</q1:AttributeName>" + 
" <q1:Operator>Equal</q1:Operator>" + 
" <q1:Value xsi:type='xsd:string'>" + Xrm.Page.getAttribute("subjectid").getValue() + "</q1:Value>" + 
" </q1:Condition>" + 
" </q1:Conditions>" + 
" </q1:Criteria>" + 
" </query>" + 
" </RetrieveMultiple>" + 
" </soap:Body>" + 
"</soap:Envelope>" + 
""; 

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); 

xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false); 
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple"); 
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 
xmlHttpRequest.setRequestHeader("Content-Length", xml.length); 
xmlHttpRequest.send(xml); 

var resultXml = xmlHttpRequest.responseXML; 
var entityNode = resultXml.selectSingleNode("//RetrieveMultipleResult/BusinessEntities/BusinessEntity"); 

var subjectNode = entityNode.selectSingleNode("q1:description"); 
alert(subjectNode); 
Xrm.Page.getAttribute("description").setValue(subjectNode); 

ответ

2

Если вы возвращаете один пункт, то я хотел бы предложить вам использовать «Получить», а не «RetrieveMultiple». Как вы уже сделали, вы можете получить поле описания, включив «описание» в список столбцов.

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>subject</entityName>" + 
     "<id>" + Xrm.Page.getAttribute("subjectid").getValue()[0].id + "</id>" + 
     "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" + 
      "<q1:Attributes>" + 
       "<q1:Attribute>description</q1:Attribute>" + 
      "</q1:Attributes>" + 
     "</columnSet>" + 
     "</Retrieve>" + 
     "</soap:Body>" + 
     "</soap:Envelope>"; 

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); 

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); 
xmlHttpRequest.send(xml); 

var resultXml = xmlHttpRequest.responseXML; 

if (resultXml.selectSingleNode("//q1:description") != null) 
{ 
    Xrm.Page.getAttribute("description").setValue(resultXml.selectSingleNode("//q1:description").nodeTypedValue); 
} 
+0

Как перчатка! Спасибо, Кэмпи. – BelgoCanadian

Смежные вопросы