对于fetchXml查询类型,请求URL太长

时间:2017-01-14 19:36:23

标签: asp.net-web-api dynamics-crm-2011 dynamics-crm-2016 fetchxml

我正在使用带有fetchxml查询参数的CRM 2016 web api,但是我的查询太长了它模拟了IN运算符,IN列表中传递的参数数量是300个元素,有时会超过这个数量。 / p>

所以我的问题是查询对于GET HTTP请求来说太大了。我试图在http消息体中发送查询,但这不起作用,那么这个问题的解决方案是什么?

以下是我使用的fetchxml查询的代码段:

 GET http://<org>/api/data/v8.0/<entity>?fetchXml=<fetch mapping="logical" distinct="true">
       <entity name="entity">
          <attribute name="new_classopportunityid" />
          <attribute name="new_trainingproduct" />
          <attribute name="new_gtgstatus" />
          <attribute name="new_scheduledstartdate" />
          <attribute name="new_scheduledenddate" />
          <attribute name="new_remainingnumberofseats" />
          <attribute name="new_liveclassroom" />
          <attribute name="new_maxlive" />
          <attribute name="new_xavieruniversity" />
          <attribute name="new_partnerlive" />
          <attribute name="new_blended" />
          <filter>
             <condition attribute="new_classopportunityid" operator="in">
                <value>001943ea-e263-e611-8158-00155d002810</value>
                <value>0071e4ea-bd9b-e611-8163-00155d002810</value>
                <value>00c32774-1c8f-e611-8161-00155d002810</value>
                <value>00d513fa-f0bb-e611-8169-00155d002810</value>
                <value>....</value>
                <value>....</value>
                <value>....</value>
             </condition>
          </filter>
       </entity>
    </fetch>

我要求的CRM web api端点是:

Error code: 414: HTTP/1.1 414 Request-URI Too Long  Response :  "<!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01\/\/EN\"\"http:\/\/www.w3.org\/TR\/html4\/strict.dtd\">\r\n<HTML><HEAD><TITLE>Request URL Too Long<\/TITLE>\r\n<META HTTP-EQUIV=\"Content-Type\" Content=\"text\/html; charset=us-ascii\"><\/HEAD>\r\n<BODY><h2>Request URL Too Long<\/h2>\r\n<hr><p>HTTP Error 414. The request URL is too long.<\/p>\r\n<\/BODY><\/HTML>\r\n" [] []

这是我从api得到的回复。

{{1}}

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:1)

使用&#34; in&#34;正如您所见,具有大量ID列表的运算符可能不是查询的最佳方式。如果您可以使用new_classopportunity过滤link-entity实体的属性会更好,如下所示:

<fetch mapping="logical" distinct="true" >
  <entity name="entity" >
    <!-- ... all your attributes ... -->
    <link-entity name="new_classopportunity" from="new_classopportunityid" to="new_classopportunityid" >
      <attribute name="new_name" />
      <filter>
        <condition attribute="statecode" operator="eq" value="0" />
      </filter>
    </link-entity>
  </entity>
</fetch>

请注意,您也可以从link-entity提取属性。在这种情况下,我提取名称并使用过滤器仅获取有效的new_classopportunity条记录。

如果您在new_classopportunity上没有可以过滤以获取相同列表的字段,请添加一个! :)