我正在创建一个代理来将被取消的文档移动到归档数据库,在复制到归档数据库之前,我想检查文档是否已经存在于归档数据库中。有些文档的主字段在数据库中是相同的,所以我不能使用这些字段来检查是否是相同的字段。是否有任何方法检查文档是否是两个数据库中的同一个文档?我发现,对于同一个文档,在两个数据库中,unid的某些部分是相同的(例如:源数据库中的unid : 613D530A7B107F46852578E9001DCC89 unid在dest数据库中: 85258289002735FB852578E9001DCC89),,但我不确定这是否是一个正确的标志。
发布于 2018-05-16 00:49:01
由于文档的unid (如果不被篡改)由从数据库副本ID计算的一部分和“创建”的转换时间戳组成,因此“相同”文档具有类似的unid并不完全是巧合。
但是,这并不是您可以依赖的,并且取决于您在归档中创建文档的方式。
如果你做了这样的事
Set docArchive = New NotesDocument( dbArchive )
Call doc.CopyAllItems( docArchive, True )
那么工会之间就没有任何关系了。
如果使用doc.CopyToDatabase
,它将取决于尝试次数,并可能导致
要识别你的文档,你必须有一个找到它的“钥匙”。
一种方法是使用同样的普遍性:
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
如果您不想直接使用通用If,可以计算一个键,或者再次使用源文档的通用If作为键:
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)
然后在按GetDocumentByKey排序的视图中从搜索或更好的位置找到归档文档:
Set docArchive = db.Search( {ArchiveKey = "} & strArchiveKey & {"}, Nothing, 0).getFirstDocument()
Set docArchive = viwLkp.GetDocumentByKey( strArchiveKey )
发布于 2018-05-16 04:43:31
对于邮件、文档或会议邀请,您可以使用$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
发布于 2018-05-17 04:25:22
我强烈反对代理任何归档。归档应使用标准Notes归档选项和字段进行处理。理想情况下,文档只存在于主数据库或存档数据库中。当文档必须存档时,只需添加一个带有正确日期的字段ExpireDate,其余的归档就应该完成(激活时)。不需要自己移动文件。
https://stackoverflow.com/questions/50364752
复制相似问题