获取查找值的属性 - javascript / CRM 2011

时间:2013-07-31 22:12:47

标签: javascript soap dynamics-crm-2011

我想用所选主题的描述填充CRM案例的描述(在选择主题之前将禁用案例描述)。 我会用它根据主题自动填充一些问题。 如何检索主题描述?我可以获得ID和主题名称,但似乎无法在网络上找到比2更多属性的任何内容。

非常感谢!

劳伦

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);

1 个答案:

答案 0 :(得分: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);
}