« Classic Notes Development; How to launch a database in Designer with Command Line Parameters | Main| How I got Lotus Connectors (LCLSX) to finally connect from our IBM i to a remote Windows DB/2 server »

Classic Notes Development: Updated code to open design elements from Notes - in Designer

Tags: LotusScript

Thanks to Stephan Wissel who pointed me in the correct direction regarding how to open design elements directly – from the Notes client with LotusScript.

My updated code (from our code synopsis database, which contain info about all databases and their code)

'    Sub OpenElementInDesigner
'    Description: Open the design element in Designer. If the current document is 
'    a fObject-document, then the database itself is opened up in designer, but if the
'    current document is a fCode-document, then the current design element is opened up 
'    directly.
'    Thanks to Stephan Wissel for pointing me in the correct direction (ref the 
'    discussionb on my blog: http://www.proudprogrammer.no/ppblog.nsf/d6plinks/GANI-8U3JDV)
Sub OpenElementInDesigner(bOpenCurrentDocument As Boolean)
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim coll As NotesDocumentCollection
    Dim docObject As NotesDocument
    Dim docSelected As NotesDocument
    Dim strNotesDir As String
    Dim strCmdAndParam As String
    Dim strServer As String
    Dim strReplicaID As String
    Dim strForm As String
    Dim strUNID As String
    Dim strParentUNID As String
    Dim nam As NotesName
    Dim ws As New NotesUIWorkspace
    Dim uidoc As NotesUIDocument
    Dim strNotesURL As String
    On Error Resume Next
    Set uidoc = ws.CurrentDocument
    strNotesURL = "notes://$(SERVERNAME)/$(REPLICAID)$(UNIDANDCMD)" 
    ' Find the whereabouts of the notes.exe - the same as designer.exe
    strNotesDir = FullTrim(session.GetEnvironmentString("NotesProgram",True))
    If Len(strNotesDir) = 0 Then Exit Sub
    ' Ensure path is OK ...
    If Right(strNotesDir, 1) <> "\" Then strNotesDir = strNotesDir & "\"
    ' Get the selected document
    Set db = session.CurrentDatabase
    If bOpenCurrentDocument = True Then
        Set docSelected = uidoc.Document
        Set coll = db.UnprocessedDocuments
        If coll.Count = 0 Then Exit Sub
        Set docSelected = coll.GetFirstDocument
    End If
    ' Get the Form so I can have different processing ...
    strForm = FullTrim(docSelected.Form(0))
    ' If I got a code segement document, then get the parent object document too
    ' Then construct the UNID and Open suffix for the URL
    Select Case strForm
        Case "fObject":
            Set docObject = docSelected
        Case "fCode":
            strParentUNID = FullTrim(docSelected.txtInheritUNID(0))
            If Len(strParentUNID) > 0 Then 
                Set docObject = db.GetDocumentByUNID(strParentUNID)
                ' Get the UNID of the Design element ...
                strUNID = FullTrim(docSelected.txtNoteinfoUNID(0))
                If Len(strUNID) > 0 Then
                    strNotesURL = Replace(strNotesURL, "$(UNIDANDCMD)", "/" & strUNID & "?Open")        
                End If
            End If
    End Select
    If docObject Is Nothing Then Exit Sub
    ' Get the whereabout of the server and database ...
    ' Note that the server is specified by it's common name.
    strReplicaID = FullTrim(docObject.txtReplicaID(0))
    strNotesURL = Replace(strNotesURL, "$(REPLICAID)", strReplicaID)
    strServer = FullTrim(docObject.txtServer(0))
    If Len(strServer) > 0 Then
        Set nam = New NotesName(strServer)
        strServer = nam.Common
        strServer = "/"
    End If
    strNotesURL = Replace(strNotesURL, "$(SERVERNAME)", strServer)
    strNotesURL = Replace(strNotesURL, "$(UNIDANDCMD)", "") ' Ensures that a database-only also will open        
    ' Finally construct the command and URL
    strCmdAndParam = |"| & strNotesDir & |designer.exe" | & strNotesURL
    ' Launch it
    Dim result As Integer
    result = Shell(strCmdAndParam, 1)
End Sub


Gravatar Image1 - you are most welcome
Emoticon stw

Post A Comment