【问题标题】:How to pass null or empty to FetchXML filters?如何将 null 或空传递给 FetchXML 过滤器?
【发布时间】:2019-08-31 19:30:30
【问题描述】:

场景:我在 Dynamics CRM 中有一个关于订单类型的文本字段。该字段与其他一些系统集成,它只接受已经声明的值列表;比如 ABC、IJK、XYZ 等。现在我可以使用高级查找来查询该字段是否包含数据。

现在在报告中,我有一个参数,它具有所有这些可能的值和一个附加的“不包含数据”,它的值是空字符串。我还为多选启用了此报告参数。但是,如果从报告参数中选择任何值,我将无法获取订单。

以下是我的 FetchXML 查询,请让我知道我在下面缺少什么。

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="invoicedetail">
   <attribute name="productid" />
    <attribute name="invoicedetailid" />
    <attribute name="tv_ordertype" />
    <order attribute="productid" descending="false" />
    <filter type="and">
        <condition attribute="tv_ordertype" operator="in" value="@Order_Types" />
    </filter>
  </entity>
</fetch>

【问题讨论】:

    标签: filter dynamics-crm-2011 fetchxml


    【解决方案1】:

    很遗憾,您不能将值(“ABC”、“IJK”、“XYZ”)与空字符串选项结合使用。想想 SSRS 是如何将空字符串解析成 FetchXml 的:

    <condition attribute="tv_ordertype" operator="in" value="" />
    

    因为in运算符有一个空字符串,所以不会有匹配结果。

    一种可行的方法是将 FetchXml 更改为使用 or 过滤器,如下所示

    <filter type="or">
        <condition attribute="tv_ordertype" operator="null" />
        <condition attribute="tv_ordertype" operator="in" value="@Order_Types" />
    </filter>
    

    现在这将返回 CRM 中与您的条件匹配的所有值或具有空 tv_ordertype

    然后您可以在 tablix / 报告级别应用其他过滤

    【讨论】:

    • 什么是“@Order_Types”?我在 FetchXML 中找不到有关以 @ 开头的此类变量的任何文档。
    • @Shadowfax 来自原始问题
    • 对,它在原始问题中,但它是一个有效的变量还是只是一些作为占位符的乱码?
    • @Shadowfax 哦,我认为您可以使用逗号分隔值,但通常会是这样:&lt;condition attribute="tv_ordertype" operator="in" &gt;&lt;value&gt;option1&lt;/value&gt;&lt;value&gt;option2&lt;/value&gt;&lt;/condition&gt;
    【解决方案2】:

    试试下面的方法

      <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
        <entity name="invoicedetail">
            <attribute name="productid" />
            <attribute name="invoicedetailid" />
            <attribute name="tv_ordertype" />
            <order attribute="productid" descending="false" />      
            <filter type='and'>         
    <condition attribute="tv_ordertype" operator="in" value="@Order_Types" />
            </filter>
        </entity>
    </fetch>
    

    【讨论】:

    • 它对我不起作用并最终出现错误:The FetchXML parameter "@Order_Types" cannot obtain multiple values. Change Parameter "@Order_Types" to single value parameter and try again
    • 我更新了我的答案,您的参数是否获取所有 Order_Types?您可以发布参数和查询的屏幕截图吗?参考链接nishantrana.me/2016/03/04/…
    【解决方案3】:

    您的 fetch XML 应该如下所示:

    <?xml version="1.0" encoding="UTF-8"?>
    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
       <entity name="invoicedetail">
          <attribute name="productid" />
          <attribute name="invoicedetailid" />
          <attribute name="tv_ordertype" />
          <order attribute="productid" descending="false" />
          <filter type="and">
             <condition attribute="tv_ordertype" operator="in"/>
                <value>@Order_Types[0]</value>
                <value>@Order_Types[1]</value>
                <!-- etc -->
             </condition>
          </filter>
       </entity>
    </fetch>
    

    【讨论】:

      猜你喜欢
      • 2018-04-14
      • 2012-08-25
      • 2016-12-11
      • 1970-01-01
      • 2013-06-24
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多