如何检查文档已经存在于 IBM Domino 中

How to check document already exist in IBM Domino

我正在创建一个代理来将取消的文档移动到存档数据库,在复制到存档数据库之前,我想检查文档是否已经存在于存档数据库中。有一些文档的主要字段在数据库中是相同的,所以我不能使用这些字段来检查它是否相同。有什么方法可以检查两个数据库中的文档是否相同?我发现对于同一个文档,unid 的某些部分在两个数据库中是相同的(例如:源数据库中的 unid:613D530A7B107F46852578E9001DCC89 dest 数据库中的 unid:85258289002735FB852578E9001DCC89), 但我不确定这是否是一个正确的标记。

由于文档的 unid(如果未被篡改)由根据数据库副本 ID 计算的部分和 "created" 的转换时间戳组成,这并非纯属巧合,"same" 文档有一个类似的单位。

但这不是您可以依赖的,并且取决于您在存档中创建文档的方式。

如果你做了类似

Set docArchive = New NotesDocument( dbArchive )
Call doc.CopyAllItems( docArchive, True )

那么unids之间就没有任何关系了。

如果您使用doc.CopyToDatabase,这将取决于尝试的次数,并且可能会导致

  • 目标中的相同单位
  • 目标中的类似 unid(文档的第一个副本)
  • 目标中的 unid 完全不同(后续副本)

要识别您的文档,您必须有 "key" 才能找到它。

一种方法是使用相同的 universalid:

Set docArchive = New NotesDocument( dbArchive )
Call doc.CopyAllItems( docArchive, True )
docArchive.Universalid = doc.Universalid
Call docArchive.Save()

然后你可以像这样检查是否存在:

On Error Resume Next
Set docArchive = dbArchive.getDocumentByUnid( doc.UniversalID )
On error Goto 0
If Not docArchive is Nothing then 'EXISTS
    ....
End If

如果你不想直接使用 universalid,你可以计算一个键或者再次使用源文档的 universalid 作为键:

Set docArchive = doc.CopyToDatabase( dbArchive )
strArchiveKey = doc.Universalid
'or compose unique key from 3 individual fields:
strArchiveKey = doc.getItemvalue( "OneField" )(0) & "-" & doc.getItemvalue( "AnotherField" )(0) & "_" doc.getItemvalue( "YetAnotherField" )(0)
Call docArchive.ReplaceitemValue( "ArchiveKey", strArchiveKey  )
Call docArchive.Save(True, True, True)

然后在按 ArchiveKey 排序的视图中通过搜索或更好的 GetDocumentByKey 找到存档文档:

Set docArchive = db.Search( {ArchiveKey = "} & strArchiveKey & {"}, Nothing, 0).getFirstDocument()

Set docArchive = viwLkp.GetDocumentByKey( strArchiveKey )

对于邮件文档或会议邀请,您可以使用 $MessageID 字段作为唯一项目,以便在存档前参考。我过去用它来为 CRM 数据库提供客户信件。邮件 ID 即使在多个邮件数据库中也是唯一的,这有助于将混乱情况降至最低。

所以,像这样的东西(未经测试,没有可用的 atm 设计器客户端)...

'you should have the destination db and the current doc as an object already

dim searchFormula$
dim collDestination as NotesDocumentCollection
dim docDestination as NotesDocument

'of course you could use a lookup view in the destination
'database instead using the less performant db.search

searchFormula$ =|$MessageID="|+cstr(docCurrent.getItemValue("$MessageID")(0))+|"|
set collDestination = dbDestination.search(searchFormula$, Nothing,1)

if not collDestination is Nothing then
 'do nothing or return document already in target database
 'set docDestination = collDestination.getFirstDocument()
else 
  'copy only if doc in destination db not found
  set docDestination = docCurrent.copytoDatabase(dbDestination)
end if

我强烈反对任何代理存档。归档应该使用标准的 Notes 归档选项和字段来处理。理想情况下,文档仅存在于主数据库或存档数据库中。当必须存档文档时,只需添加一个具有正确日期的 ExpireDate 字段,剩下的就由存档完成(激活时)。无需自己移动文档。