簡體   English   中英

Dynamics AX 2012綜合QueryBuild對象

[英]Dynamics AX 2012 Complex QueryBuild Object

嘗試過濾AX中的特定數據范圍並遇到問題。

這就是我要用偽代碼執行的操作。

(start >= now-30 && (end == null || end >= now-30))
||
(end >= now-30 && (start == null || start >= now-30))
||
(start >= now-30 && end >= now-30)

這是我試圖做到的

類聲明

QueryBuildRange filterDates;

DS INIT方法

filterDates=this.query().dataSourceName('LogTable').addRange(fieldNum(LogTable,startDateTime));    
filterDates=this.query().dataSourceName('LogTable').addRange(fieldNum(LogTable,endDateTime));    

DS執行方法

filterDates.value(strFmt("(%1 >= %3 && (%2 == %4 || %2 >= %3)) || (%2 >= %3 && (%1 == %4 || %1 >= %3)) || (%1 >= %3 && %2 >= %3)", fieldStr(LogTable, startDateTime), fieldStr(LogTable, endDateTime), currentTimeMinus30Mins, DateTimeUtil::minValue()));

AX似乎幾乎忽略了我輸入的所有completex查詢。

謝謝

只要您的偽代碼中的邏輯正確,我仍然可以在您的DS EXECUTEQUERY方法中看到一些缺陷:

  • 整個表達式必須用括號括起來。
  • 每個子表達式都必須用自己的括號括起來。
  • DateTimeUtil::toStr(...)丟失。

嘗試如下更改代碼:

filterDates.value(strFmt("(((%1 >= %3) && ((%2 == %4) || (%2 >= %3))) || ((%2 >= %3) && ((%1 == %4) || (%1 >= %3))) || ((%1 >= %3) && (%2 >= %3)))",
                        fieldStr(LogTable, startDateTime),
                        fieldStr(LogTable, endDateTime),
                        DateTimeUtil::toStr(currentTimeMinus30Mins),
                        DateTimeUtil::toStr(DateTimeUtil::minValue())));

您應該可以簡化一下:

filterDates.value(strFmt("(((%1 >= %3) || (%1 == %4)) && ((%2 >= %3) || (%2 == %4)) && !((%1 == %4) && (%2 == %4)))",
                        fieldStr(LogTable, startDateTime),
                        fieldStr(LogTable, endDateTime),
                        DateTimeUtil::toStr(currentTimeMinus30Mins),
                        DateTimeUtil::toStr(DateTimeUtil::minValue())));

另外,我看不到在DS INIT METHOD中兩次初始化filterDates的任何原因。 實際上,您可以在此范圍內使用其他字段,不必為startDateTime或endDateTime:

filterDates = SysQuery::findOrCreateRange(this.query().dataSourceTable(tableNum(LogTable)), fieldNum(LogTable, RecId));

PS:我不太清楚如何在此類表達式中使用utcDateTime值-就我所記得, DateTimeUtil::toStr(...)應該可以工作。

我認為您的邏輯有缺陷,這可能就是為什么它不起作用!

我想您想使用兩個日期時間字段startend進行時間點搜索,如果未結束, end為空。

要搜索30天前有效的記錄, 唯一需要的條件是:

(start <= now-30 && (end == null || end >= now-30))

在數據源的executeQuery中實現:

public void executeQuery()
{
    QueryBuildDataSource qds = this.query().dataSourceTable(tableNum(LogTable));        
    SysQuery::findOrCreateRange(qds, fieldNum(LogTable,StartDateTime)).value('..'+queryValue(currentTimeMinus30Mins));
    SysQuery::findOrCreateRange(qds, fieldNum(LogTable,EndDateTime)).value('"",'+queryValue(currentTimeMinus30Mins+'..');
    super();
}

以上適用於日期字段,我認為它也適用於日期時間字段。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM