Friday, May 26, 2006

Show-n-Tell Thursday - Updating FolderReferences

We recently enabled FolderReferences on a database that already contained a lot of documents. According to everything I've read, you can only get FolderReferences for documents added to a folder after the property is enabled, but we needed to get it set for all the existing documents as well. I found a pretty simple way to do it. Just add an action to your folder template and refresh the design of all folders (or add the action to each folder) and run on selected documents.

Here's the code:

Sub Click(Source As Button)
On Error Goto errhand
Dim w as new notesuiworkspace
Dim s As New notessession
Dim db As notesdatabase
Dim v As notesview
Dim uiv as notesuiview
Dim doc As notesdocument
Dim dc As notesdocumentcollection

Set db = s.currentdatabase
Set dc = db.unprocesseddocuments
Set uiv = uiw.currentview
Set v = uiv.view

Set doc = dc.getfirstdocument
While Not doc Is Nothing
Call doc.RemoveFromFolder(v.Name)
Call doc.PutInFolder(v.Name, False)
nextDoc:
Set doc = dc.getnextdocument(doc)
Wend

Call uiv.deselectall
Call w.ViewRefresh

Exit Sub
errhand:
Print "Error at line " & Erl & ": " & Error & " for UNID " & doc.universalid
Resume nextDoc
End Sub


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


Show-n-tell thursday
Show-n-Tell Thursday

Thursday, May 04, 2006

Show-n-Tell Thursday - Sending links to a view; open in a frameset

One of the things we do pretty frequently is allow users to send notifications with links to views/folders from various applications. This is usually to let someone know that data has changed in the folder, or that a flag has been set on the folder configuration document to indicate a change of status for the group of documents contained in the folder. The problem is, if you send a doclink to a view, it opens with the default navigator, rather than in the frameset that you've designed to contain navigation. I've gotten around this by making use of Julian's excellent DXL button creator class.

First, copy the code into a script library (or use as is in .lss format). In the Globals of each view/folder, include the script library, and add this sub:


Sub CreateButton(db As notesdatabase, thisv As notesview, mailDoc As notesdocument,
body As notesrichtextitem, label as string, frameName as string)
On Error Goto errhand
Dim button2 As New RichTextButton
Dim result As String
Dim openDatabaseString As String
Dim openViewString As String
Dim stringToPass As String
Dim frameToPass As String
Dim filepath As String
Dim viewName As String

filepath = Cstr(Replace(db.filepath, "\", "\\"))
viewname = Cstr(Replace(thisV.Name, "\", "\\"))

openDatabaseString = |@Command( [FileOpenDatabase]; "| + db.server + | ":"| + filepath + | ");|
openViewString = |@Command([OpenView]; "| + viewName + |");|
frameToPass = |@SetTargetFrame("| + frameName + |");|
stringToPass = openDatabaseString & Chr(13) & Chr(10) & "@UpdateFormulaContext;" & _
Chr(13) & Chr(10) & frameToPass & Chr(13) & Chr(10) & openViewString

'** append a Formula button to the body
Call button2.SetLabel(label)
Call button2.SetEdgeType(RTB_SQUARE)
Call button2.SetButtonLanguage(RTB_FORMULA)
Call button2.SetCode( stringToPass )
Call body.AddNewline(1)
result = button2.AppendButton(body)
If (result <> "") Then
Call body.AppendText("There was an error creating the button. " & result)
End If

Call maildoc.Save(True, True)
Exit Sub
errhand:
Msgbox "CreateButton error at line " & Erl & ": " & Error
Exit Sub
End Sub


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


Here's what our action bar button looks like:


Sub Click(Source As Button)
On Error Goto errhand
Dim s As New notessession
Dim w As New notesuiworkspace
Dim db As notesdatabase
Dim thisV As notesview
Dim mailDoc As notesdocument
Dim body As notesrichtextitem

Set db = w.currentdatabase.database
Set thisV = w.currentview.view
Set mailDoc = db.createdocument

mailDoc.Form = "Memo"
mailDoc.Subject = thisV.Name & " is ready for your review."
mailDoc.SendTo = "Esther Strom"

Set body = New notesrichtextitem(mailDoc, "Body")
Call body.appendtext(s.commonusername & " has indicated that the " & thisV.Name & _
" catalog is ready for MarComm review. " )
Call body.addnewline(2)

'create button here
Call CreateButton(db, thisv, mailDoc, body, "Open Bid Folder", "contentFrame")

Call mailDoc.Send(False)
Call maildoc.RemovePermanently(True)
Msgbox "MarComm has been notified"

Exit Sub
errhand:
Msgbox "Info Ready for MarComm error at line " & Erl & ": " & Error
Exit Sub
End Sub


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


The recipient then receives a nicely-formatted email (if you bother to do any formatting) containing a button that will open the folder in the context of the frameset as intended.



Show-n-tell thursday
Show-n-tell Thursday