【问题标题】:Get attribute of lookup value - javascript / CRM 2011获取查找值的属性 - javascript / CRM 2011
【发布时间】:2013-07-31 22:12:47
【问题描述】:

我想用所选主题的描述填充 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);

【问题讨论】:

    标签: javascript soap dynamics-crm-2011


    【解决方案1】:

    如果您要退回一件商品,那么我建议您使用“Retrieve”而不是“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);
    }
    

    【讨论】:

    • 像手套一样!谢谢坎佩。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 2015-01-15
    • 2012-07-09
    相关资源
    最近更新 更多