Monday, March 27, 2006

Show-n-Tell Thursday

Originally posted on February 23, 2006

Here's my first contribution to this new web-wide feature. It took me a while to come up with something small that I thought may be useful. This is a kinda sorta pseudo-relational behavior you can incorporate into a view.

Say you have a set of response documents that contain the fields you want to display in a view. But, instead of opening those documents when they are clicked, you would rather open their parent document. And you display the response documents in other views, but in those views you want to open the response document (so you don't want to put code in the QueryOpen of the response form). What do you do?

Put this code in the QueryOpenDocument event of the view and the parent document will open instead of the document that you double-clicked to open.

UPDATE: I added some error handling for orphans, unreadable parents and replication conflicts. Don't know why I didn't think of it, other than that we hadn't run into those problems in the view where I used the code.



Sub Queryopendocument(Source As Notesuiview, Continue As Variant)
Dim doc As NotesDocument
Dim docParent As NotesDocument
Dim ws As New NotesUIWorkspace
Dim openIt As Integer

openIt = False
Set doc = Source.Documents.GetFirstDocument
If doc.IsResponse Then
Continue = False
If doc.HasItem("$Conflict") Then
Messagebox "Opening replication conflicts is not allowed in this view",48,"Open Document"
Exit Sub
End If
Set docParent = doc.ParentDatabase.GetDocumentByUNID(doc.ParentDocumentUNID)
If docParent Is Nothing Then
openIt = False
Elseif docParent.IsDeleted Or Not docParent.IsValid Then
openIt = False
Else
openIt = True
End If
If openIt Then
Call ws.EditDocument(False,docParent)
Else
Messagebox "Cannot open requested document. This may be because " &_
"the selected document is an orphan or because " &_
"you do not have access to the requested document.",48,"Open Document"
Exit Sub
End If
End If
End Sub


This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.

No comments: