Lotus Script / What are "session" "workspace" "db"

I start all my LotusScript with this type of code. I think it would be beneficial if I had some understanding of what I’m doing.

I understand that I need to get a handle on my UIDOC and DOC.

I don’t understand what “session” “workspace” and “db” are for. I just mindlessly throw them in because it makes things work. If someone would like to explain to me what they are for and what I need to know about them, I would really appreciate it.

Sub Click(Source As Button)

Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc = workspace.CurrentDocument

Dim doc As NotesDocument

Set doc = uidoc.Document

Subject: Lotus Script / What are “session” “workspace” “db”

The NotesSession is the root class for all back-end Notes objects. If you don’t need to use any back-end objects (such as getting the current database without having a UI access method) or can access the back-end objects via the UI (such as using Source.Document in a form event), then you don’t need the session object.

The NotesUIWorkspace is the foundation object for the front-end (UI) Notes objects. If you need to access the UI and aren’t given a built-in hook (like the Source As NotesUIDocument hook in form events), then you need to create a workspace object as a context to get the objects you are looking for.

In the snippet you posted, you probably don’t need either the session or the database objects, since you are likely working only with the current document:

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Set uidoc = ws.CurrentDocument 'gets a handle to the open UI document

Set doc = uidoc.Document 'gets a handle to the back-end document

'code here can access, modify and save the uidoc or the back end doc

End Sub

If you were doing exactly the same thing in a form event, you wouldn’t necessarily need the workspace either:

Sub QuerySave(Source As NotesUIDocument, Continue As Variant)

'there is already a handle called Source that is equivalent to

'workspace.CurrentDocument

Dim doc As NotesDocument

Set doc = Source.Document

'code here

End Sub

If you need to access something else in the database, like a view or another document, then you would need to create a handle to the database.

Subject: Thank you

Thank you Stan. This is exactly the type of explanation I needed. This is a good base for me to move forward learning how Notes works.

Subject: RE: Thank you

A picture tells more than thousand words:http://www.advancedclp.com/graphics/tours/273/lsclassestop.gif

Subject: Lotus Script / What are “session” “workspace” “db”

Not sure if it’s in 7, but in 6 when you’re in designer, there’s a ‘home page’ thing on the right side of the screen when you start designer with quick links at the top. If you select ‘domino object model’, you see a nice visual of how everything relates - who contains what.

This stuff used to be available in a poster - not sure if it’s still around.

Doug