代码之家  ›  专栏  ›  技术社区  ›  Frank Yuan

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

  •  0
  • Frank Yuan  · 技术社区  · 6 年前

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

    3 回复  |  直到 6 年前
        1
  •  5
  •   Tode    6 年前

    由于文档的unid(如果未被篡改)由从数据库副本ID计算的一部分和“创建”的转换时间戳组成,“相同”文档具有相似的unid,这并非纯粹巧合。

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

    如果你做了这样的事

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

    那么unids就不会有任何关系了。

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

    • 目标中的unid相同
    • 目标中的类似unid(文件的第一份副本)
    • 目标中完全不同的unid(后续副本)

    要识别您的文档,您必须拥有查找它的“密钥”。

    一种方法是使用相同的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 )
    
        2
  •  1
  •   qu1cke    6 年前

    对于邮件文档或会议邀请,您可以在存档之前将$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
    
        3
  •  0
  •   D.Bugger    6 年前

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