2017-08-30 64 views
0

我想建立僅包含最近的文檔(更新超過2個月)的圖。我使用的這個選擇表現公式:Notes公式語言日期差異

SELECT @IsAvailable($Conflict) and docForm="ServiceOrders" and (@Today-PosDesValidFrom)<5259600 

凡5259600是2個月秒鐘,因爲我讀的是 - 操作員返回秒的時間跨度。 我認爲我沒有任何結果。

回答

1

從不在視圖選擇公式中使用@Today或@Now。視圖索引將永遠不會是最新的,因此更新任務將不斷運行以刷新索引。這會影響性能的負面影響。

你應該做的是每天(在你的情況下可能每晚)代理將標記文檔顯示在視圖中。 要儘可能快地創建代理,請在其中一個列中處理顯示日期的視圖。

絕對最快的會是這樣的:
1)創建一個名爲(LookupServiceOrdersByValidDate)的隱藏視圖。
2)第一列將包含字段名稱PosDesValidFrom(我將假設它是一個日期字段,否則您需要將其轉換爲日期),並按降序排序。轉到列的信息框中的第四個選項卡,並確保將其設置爲日期/時間。
enter image description here
3)創建第二列,在其中顯示文本字段DisplayIn2MonthView。按降序排序。
4)保存視圖。

您現在可以通過使用代理視圖可以循環。由於它是按照最新的排在最前面的順序排列的,所以只要您在兩個月以前到達日期,就可以停止代理並完成任務。

該腳本會是這個樣子:

Dim session as New NotesSession 
Dim db as NotesDatabase 
Dim view as NotesView 
Dim col as NotesViewEntryCollection 
Dim entry as NotesViewEntry 
Dim doc as NotesDocument 
Dim validDate as NotesDateTime 
Dim cutoffDate As NotesDateTime 

' Get current date and time and go back 2 months 
Set cutoffDate = New NotesDateTime(Now()) 
Call cutoffDate.AdjustMonth(-2) 
' Drill down to view 
Set db = session.CurrentDatabase 
Set view = db.GetView("(LookupServiceOrdersByValidDate)") 
' Create a collection of all entries in the view and loop through them 
Set col = view.AllEntries 
Set entry = col.GetFirstEntry() 
Do Until entry is Nothing 
    ' Get value in first column in view and use it to create new DateTime object 
    validDate = New NotesDateTime(entry.ColumnValues(0)) 
    ' Check if we are within the 2 month cutoff date 
    If Cdat(validDate.dateOnly)>=Cdat(cutoffDate) Then 
     ' Get document and set flag to display 
     Set doc = entry.Document 
     Call doc.ReplaceItemValue("DisplayIn2MonthView","Yes") 
     Call doc.Save(True,False) 
    Else 
     ' We are beyond the cutoff date, but we need to clear old flags. 
     ' Read the value in the second column and see if it is "Yes" 
     If entry.ColumnValues(1)="Yes" Then 
      Set doc = entry.Document 
      Call doc.ReplaceItemValue("DisplayIn2MonthView","") 
      Call doc.Save(True,False) 
     Else 
      ' Since all "Yes" values should be at the top, if we 
      ' get here there should be no more flagged documents. 
      Exit Do 
     End If 
    End If 
    Set entry = col.GetNextEntry(entry) 
Loop 
Print "All done." 

最後,修改顯示文檔的視圖。您應該使用Form字段,而不是docForm。將選擇公式設置爲
SELECT [email protected]($Conflict) AND Form="ServiceOrders" AND DisplayIn2MonthView="Yes" 該視圖現在應該只包含ServiceOrder文檔和最近2個月內的ValidDate。 如果你真的想只複製/保存衝突的觀點,確保視圖設置爲一個層次顯示響應文件(取消選中該複選框): enter image description here

+0

這是一個非常聰明的想法,不幸的事情是我沒有權限在表單中創建新字段。 – Curunir

+0

出於某種原因,我在cutoffDate類型不匹配:CDat(validDate.dateOnly)> = CDat(cutoffDate) – Curunir

+0

@exasswede這種解決方案適用於我,但問題是,一個新的訂單將不會出現,直到代理在視圖上運行。 – Curunir