2013-07-31 45 views
0

我想用所選主題的描述來填充CRM案例的描述(案例描述將被禁用,直到選定主題爲止)。 我會用它來根據主題自動填充一些問題。 如何檢索主題描述?我可以獲得ID和主題名稱,但似乎無法在網絡上找到比這些更多屬性的任何內容。獲取查找值的屬性 - javascript/CRM 2011

非常感謝!

洛朗

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」。正如以上所做的那樣,您可以通過在列列表中添加「description」來獲取描述字段。

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

就像手套一樣!感謝Campey。 – BelgoCanadian