How to Check for a Deletion Stub Using LotusScript
This gem from the KnowledgeBase caught my attention the other day. Since I don't often design by storing the UNID of one document in another document, I don't think I've ever been bitten by this. But it's not an intuitive thing... You think that if the document is deleted, it's no longer there. So read on and be warned... :-)
------------------------------
How to Check for a Deletion Stub Using LotusScript
Document Number:
1085749
Problem
You have a UNID for DocumentA that is
stored in DocumentB. Now DocumentA is Deleted. If in an agent or
event you use the UNID stored in DocumentB to retrieve DocumentA using
the Doc = DB.Getdocumentbyunid(UNID), you do not get an error. If
you continue to process the using Doc you will probably want to generate
an error similar to the following:
If you use this code stub you can generate
errors.
Set Doc = DB.Getdocumentbyunid(UNID)
If Not(Doc is Nothing) Then
....
you think that you have a valid document but it could be a deletion stub
End
Content
The solution is to test for BOTH Doc
is Nothing and Doc.Size <> 0. Here is a sample function:
Function IsDocThere(TestDoc As NotesDocument)
As Integer
IsDocThere
= False
If
TestDoc Is Nothing Then Exit Function
If
TestDoc.Size = 0 Then
Set TestDoc = Nothing
Exit Function
End
If
IsDocThere
= True
End Function
You can just call this from your code
with this. Upon return, if there is a deletion stub, the Doc is set
to nothing so that it does not interfere with tests, and returns False
regardless of whether it is a deletion stub or a non-existing document.
If IsDocThere(Doc) Then
........
Do Some stuff with document
Else
......... Process error if necessary
End If



Comments
Posted by Jerry Carter At 11:39:45 On 12/12/2003 | - Website - |