Error 4091: "Invalid universal id"

LotusScript Error 4091: "Invalid universal id" occurs when your code uses NotesDatabase.GetDocumentByUNID(unid) but the database cannot find a matching document for that specific 32-character string. This crash happens because the method does not gracefully return Nothing when a lookup fails; it throws a runtime exception instead.
LotusScript

Create a function to test the document

Function GetDocSafely(db As NotesDatabase, unid As String) As NotesDocument
    On Error 4091 GoTo Error4091
    Set GetDocSafely = db.GetDocumentByUNID(unid)
    Exit Function
Error4091:
    Set GetDocSafely = Nothing
    Exit Function
End Function

Written by fbrefere001

Posted by fbrefere001 on Friday June 12, 2026