FetchXML 中的会计日期和“早于”日期/时间查询运算符

 

发布日期: 2017年1月

适用于: Dynamics 365 (online),Dynamics 365 (on-premises),Dynamics CRM 2016,Dynamics CRM Online

Microsoft Dynamics 365(在线或本地) 中的 FetchXML 查询可以在查询中使用特殊会计日期值和早于子句作为日期和时间值。 例如,FetchXML 查询可以查找满足上一会计月内,或早于 15 分钟严重性高的紧急案例条件的所有订单。。

备注

对于所有会计日期查询,FetchXML 查询使用组织的会计年度设置。

本主题内容

使用 FetchXML 会计日期条件运算符

使用“早于”子句作为日期和时间值

使用 FetchXML 会计日期条件运算符

下面的示例显示一个 FetchXML 表达式,该表达式根据组织的会计年度设置查找在上一会计期间内完成的所有订单。 例如,如果组织使用会计月,则查询返回在上一会计月内完成的订单。 如果组织使用会计季度,则查询返回在上一会计季度内完成的订单。 如果组织使用会计半年期,则返回在上一会计半年期内完成的订单。

<fetch>
 <entity name="order">
  <attribute name="name"/>
  <filter type="and">
   <condition attribute="datefulfilled" operator="last-fiscal-period"/>
  </filter>
 </entity>
</fetch>

以下示例演示一个 FetchXML 表达式,该表达式查找在会计年度 2013 中创建的所有客户。

<fetch>
 <entity name="account">
  <attribute name="name"/>
  <filter type="and">
   <condition attribute="createdon" operator="in-fiscal-year" value="2013"/>
  </filter>
 </entity>
</fetch>

下面的示例演示一个 FetchXML 表达式,该表达式根据组织的会计年度设置查找预计结束日期在今后三个会计年度内的所有商机。x 的值在 condition 标记的 value 属性中指定。

<fetch>
 <entity name="opportunity">
  <attribute name="name"/>
  <filter type="and">
   <condition attribute="estimatedclosedate" operator="next-x-fiscal-years" value="3"/>
  </filter>
 </entity>
</fetch>

下面的示例演示一个 FetchXML 表达式,该表达式根据组织的会计年度设置查找在任意会计年度的第三个期间内完成的所有订单。 会计期间值在 condition 标记的 value 属性中指定。 如果组织使用会计月,该查询将返回第三月的结果。 如果组织使用会计季度,该查询将返回第三季度中结果。 如果组织使用会计半年期,将不返回任何结果;只有两个半年期,因此提供的值超出范围。

<fetch>
 <entity name="order">
  <attribute name="name"/>
  <filter type="and">
   <condition attribute="datefulfilled" operator="in-fiscal-period" value="3"/>
  </filter>
 </entity>
</fetch>

下面的示例演示一个 FetchXML 表达式,该表达式根据组织的会计年度设置查找在会计年度 2013 的第三个期间内完成的所有订单。 如果组织使用会计月,该查询将返回第三月的结果。 如果组织使用会计季度,该查询将返回第三季度中结果。 如果组织使用会计半年期,将不返回任何结果;只有两个半年期,因此提供的值超出范围。

<fetch>
 <entity name="order">
  <attribute name="name"/>
  <filter type="and">
   <condition attribute="datefulfilled" operator="in-fiscal-period-and-year">
    <value>3</value>
    <value>2013</value>
   </condition>
  </filter>
 </entity>
</fetch>

下面的示例演示一个 FetchXML 聚合表达式,该表达式将完成的订单总金额相加并按会计半年期和会计年度对结果进行分组。

<fetch aggregate="true">
 <entity name="order">
  <attribute name="totalamount" aggregate="sum" alias="total"/>
  <attribute name="datefulfilled" groupby="true" dategrouping="fiscal-period"/>
 </entity>
</fetch>

使用“早于”子句作为日期和时间值

以下示例描述,查找早于 30 分钟的事件的 FetchXML。

<fetch>
  <entity name="incident">
    <attribute name="title" />
    <attribute name="ticketnumber" />
    <attribute name="createdon" />
    <attribute name="incidentid" />
    <filter type="and">
      <condition attribute="createdon" operator="olderthan-x-minutes" value="30" />
    </filter>
  </entity>
</fetch>

使用以下语法指定 FetchXML 表达式中的各个早于子句。

子句

语法

X 分钟以前

<condition attribute="<AttributeName>" operator="olderthan-x-minutes" value="<VALUE>" />  

备注

该子句不受具有 DateOnly 行为的日期和时间属性的支持。详细信息:DateOnly 行为不支持的日期和时间查询运算符

X 小时以前

<condition attribute="<AttributeName>" operator="olderthan-x-hours" value="<VALUE>" />

备注

该子句不受具有 DateOnly 行为的日期和时间属性的支持。详细信息:DateOnly 行为不支持的日期和时间查询运算符

X 天以前

<condition attribute="<AttributeName>" operator="olderthan-x-days" value="<VALUE>" />

X 周以前

<condition attribute="<AttributeName>" operator="olderthan-x-weeks" value="<VALUE>" />

X 个月以前

<condition attribute="<AttributeName>" operator="olderthan-x-months" value="<VALUE>" />

X 年以前

<condition attribute="<AttributeName>" operator="olderthan-x-years" value="<VALUE>" />

备注

除了 X 个月以前子句,所有其他早于子句只有当您使用 CRM Online 2015 更新 1 或 Microsoft Dynamics 365(内部部署)时才可用。

另请参阅

使用 SDK 程序集通过查询检索数据
使用 FetchXML 构建查询
使用在 FetchXML 的左外部联接来查询“不在”记录。

Microsoft Dynamics 365

© 2017 Microsoft。 保留所有权利。 版权