在Javascript中通过SOAP检索所有实体(CRM 2011)

时间:2014-04-10 17:53:28

标签: soap dynamics-crm-2011 dynamics-crm dynamics-crm-online

使用以下SOAP查询,我试图获取解决方案中的所有实体,但它不返回实体。也许第二只眼可能有所帮助。你看到我看不到的任何错误吗?谢谢!

JCL.RetrieveAllEntitiesRequest = function (fnCallBack) {
        /// Returns a sorted array of entities
        var request = "";
        request += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
        request += "  <s:Body>";
        request += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
        request += "      <request i:type=\"a:RetrieveAllEntitiesRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
        request += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
        request += "          <a:KeyValuePairOfstringanyType>";
        request += "            <b:key>EntityFilters</b:key>";
        request += "            <b:value i:type=\"c:EntityFilters\" xmlns:c=\"http://schemas.microsoft.com/xrm/2011/Metadata\">Entity</b:value>";
        request += "          </a:KeyValuePairOfstringanyType>";
        request += "          <a:KeyValuePairOfstringanyType>";
        request += "            <b:key>RetrieveAsIfPublished</b:key>";
        request += "            <b:value i:type=\"c:boolean\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">true</b:value>";
        request += "          </a:KeyValuePairOfstringanyType>";
        request += "        </a:Parameters>";
        request += "        <a:RequestId i:nil=\"true\" />";
        request += "        <a:RequestName>RetrieveAllEntities</a:RequestName>";
        request += "      </request>";
        request += "    </Execute>";
        request += "  </s:Body>";
        request += "</s:Envelope>";

        return JCL._ExecuteRequest(request, "Execute", JCL._RetrieveAllEntitiesResponse, fnCallBack);
    };

JCL._ExecuteRequest = function (sXml, sMessage, fInternalCallback, fUserCallback) {
        'use strict';

    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", JCL.server + "/XRMServices/2011/Organization.svc/web", (fUserCallback !== null));
    xmlhttp.setRequestHeader("Accept", "application/xml, text/xml, */*");
    xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/" + sMessage);

    if (fUserCallback !== null) {
        // asynchronous: register callback function, then send the request.
        xmlhttp.onreadystatechange = function () {
            fInternalCallback.call(this, xmlhttp, fUserCallback);
        };

        xmlhttp.send(sXml);
    } else {
        // synchronous: send request, then call the callback function directly
        xmlhttp.send(sXml);
        return fInternalCallback.call(this, xmlhttp, null);
    }
};

@Paul Way回复给我后更新: 这是我在CRM Data Detective中选择需要调查的实体时收到的错误消息。我无法向该实体添加任何字段,这就是为什么我使用CRM Data Detective来找出我可以删除哪个字段的原因,但是碰巧该解决方案也无法处理具有最大属性数的实体。你能看看保罗吗?非常感谢你!

enter image description here

2 个答案:

答案 0 :(得分:1)

好吧,我很尴尬:)

我已更新CRM Data Detective和JCL库以支持CRM 2011 UR 12。

https://crmdatadetective.codeplex.com/

https://github.com/paul-way/JCL

问题与如何解析返回的XML有关。如果这可以解决您的问题,请告诉我......

答案 1 :(得分:0)

CRM 2011 SDK包含一些很好的示例代码...

http://msdn.microsoft.com/en-us/library/gg594428.aspx