FetchXML 中的會計年度日期和 "older than" 日期/時間查詢運算子

 

發行︰ 2016年11月

適用於: Dynamics CRM 2015

Microsoft Dynamics CRM 2015 和 Microsoft Dynamics CRM Online 2015 更新 中的 FetchXML 查詢可以使用特殊會計年度日期值和 older than 子句做為查詢中的日期和時間值。 例如,FetchXML 查詢可以尋找上一個會計月份完成的所有訂單,或是超過 15 分鐘且嚴重性較高的緊急案例。

注意

針對所有會計年度日期查詢,FetchXML 查詢會使用組織的會計年度設定。

本主題內容

使用 FetchXML 會計年度日期條件運算子

使用「older than」子句做為日期和時間值

使用 FetchXML 會計年度日期條件運算子

下列範例顯示 FetchXML 運算式依據組織的會計年度設定找出所有上個會計期間完成的訂單。 例如,如果組織使用會計年度月份,查詢回傳上一個會計年度完成的訂單。 如果組織使用會計季度,查詢會回傳上一個會計季完成的訂單。 如果組織使用半年度的會計算法,查詢會回傳上半年完成的訂單。

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

下列範例顯示找到所有於 2013 會計年度建立的所有客戶的 FetchXML 運算式。

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

下列範例顯示依據組織的會計年度設定,使用估計的結案日期 (之後的三個會計年度) 找到所有商機的 FetchXML 運算式。x 的值在條件標記屬性值中指定。

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

下列範例顯示 FetchXML 運算式依據組織的會計年度設定找出任何三個會計期間完成的訂單。 此會計週期的值在條件標記屬性值中指定。 如果組織使用會計年度月份,查詢會回傳第三月後的結果。 如果組織使用會計季度,查詢會回傳第三季後的結果。 如果組織使用會計半年度,將不會傳回值。一年只分為兩個半年,因此提供的值會超出範圍。

<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>

使用「older than」子句做為日期和時間值

下列範例將顯示尋找超過 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 運算式中的各種 older than 子句。

子句

語法

早於 X 分鐘

<condition attribute="<AttributeName>" operator="olderthan-x-minutes" value="<VALUE>" />
> [!NOTE] >

此子句不可做為具有 DateOnly 行為的日期和時間屬性使用。其他資訊:DateOnly 行為不支援日期和時間查詢運算子

早於 X 小時

<condition attribute="<AttributeName>" operator="olderthan-x-hours" value="<VALUE>" />
> [!NOTE] >

此子句不可做為具有 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 個月子句之外,所有其他 older than 子句只有在您使用 Microsoft Dynamics CRM Online 且已將 Dynamics 365 執行個體更新至 CRM Online 2015 更新 1 時才能使用。

另請參閱

使用查詢擷取資料
使用 FetchXML 建立查詢
在 FetchXML 中使用左外部聯結,查詢記錄 "not in"

© 2017 Microsoft. 著作權所有,並保留一切權利。 著作權