URL to launch attachment of first document in a category

Is there a way to construct a URL that will launch the attachment in the first document of the view for a specific category?

For example, a view titled Reports has several categories, one being Monthly Results, which contains several documents each with a file attachment. I want the URL to launch the attachment in the first document of the Monthly Results category of the Reports view.

The first document will always be the latest month. When a new month is added, the same URL will automatically launch the attachment in that document. This way the URL link never has to change; it will always know to launch the attachment for the most recent month.

Thank you.

Subject: URL to launch attachment of first document in a category

Sure – use an agent to find the attachment and print a redirection URL back to the browser. In LotusScript, a redirection URL that does not reflect the real URL back to the browser is enclosed in double square brackets. You will want to use the Path_Info CGI variable to get the relative URL of the agent; using Strleftback will allow you to get the URL of the database to use in building the redirection URL. This may not be the BEST way to code the agent, but it’ll work:

Dim s As New NotesSession

Dim context As NotesDocument

Set context = s.DocumentContext

Dim redirectPath As String

redirectPath = Strleftback(context.GetItemValue(“Path_Info”)(0), “/”)

Dim db As NotesDatabase

Set db = s.CurrentDatabase

Dim v As NotesView

Set v = db.GetView(“Reports”)

Dim nav As NotesViewNavigator

Set nav = v.CreateViewNavFromCategory(“Monthly Results”)

Dim targetDoc As NotesDocument

Set targetDoc = nav.GetFirstDocument

Dim attNames As Variant

attNames = Evaluate(|@AttachmentNames|, targetDoc)

Dim unid As String

unid = targetDoc.UniversalID

Print “[[” + redirectPath + “/Reports/” + unid + “/$File/” + attNames(0) + “]]”

You will want to add error checking, logging and so on to handle the cases where the category isn’t found, the first document doesn’t contain an attachment, and so forth. (Never trust the simple stuff posted here as examples as production code.)