Domino.Doc (Lotus Domino Document Manager) Sample API code to access library and get cabinets using setup Notes-based form. Note: Assumes script library functions. However, these are included in this document, too. ___________________________________________________ FORM EVENTS: (Global Declarations) Dim w As NotesUIWorkspace ' set in postopen Dim theApi As Variant ' the domino.doc api object Dim theLibrary As Variant ' the library chosen by user when successfully retrieved Dim uiDoc As NotesUIDocument ' current document, front-end Dim userpwd As String ' password entered by user Sub Postopen(Source As Notesuidocument) ' set workspace and uiDoc up Set w = New NotesUIWorkspace Set uiDoc = w.CurrentDocument ' setup d.doc api Set theApi = CreateObject("DominoDoc.API") End Sub Sub Queryclose(Source As Notesuidocument, Continue As Variant) Set theCabinet = Nothing Set theLibrary = Nothing Set theAPI = Nothing End Sub ___________________________________________________ LOAD LIBRARY BUTTON: Notes: Assumes field containing library in current form Button prompts for password, and populates field with cabinetlist for user selection of cabinet Sub Click(Source As Button) ' *** notes for global dims used by button *** ' w - uiworkspace, ' theApi - d.doc api ' uiDoc - this current doc's front-end ' all above dims should already be created/initialized during postopen ' theLibrary - global, but set by this button ' userpwd - global, but set by this button ' working dims from form Dim libsvrnm As String ' server name for library Dim libpath As String ' library file path Dim askpwd As Variant ' prompt response from user for password Dim userpwd As String ' password entered by user Dim cablist As Variant ' list of cabinets in library Dim doc As NotesDocument ' backend for uiDoc ' ddoc additional dims Dim theCabinets As Variant ' this list of cabinets from which user will select ' get backend Set doc=uiDoc.Document ' get form values libsvrnm = uiDoc.FieldGetText("CFD_LibraryServer") libpath = uiDoc.FieldGetText("CFD_LibraryPath") If (libsvrnm = "" Or libpath="") Then Print "No library server / path to use to open library. Quit." Exit Sub End If ' prompt user for password to access library askpwd = w.Prompt (PROMPT_OKCANCELEDIT, "Notes Password", "Please enter your password for logon to the Library.") If Isempty (askpwd) Then ' quit - no password entered Print "No password entered. Quit." Exit Sub End If ' set the password userpwd= Cstr(askpwd) ' login and pass library info Set theLibrary = GetLibraryViaNotes (theAPI, libsvrnm, libpath, userpwd) If (theLibrary Is Nothing) Then ' quit, unable to load library Print "Unable to load library or library is not master library. Quit." Exit Sub End If ' retrieve list of cabinets Set theCabinets = theLibrary.Cabinets ' populate the cabinets list field and refresh doc cablist = GetCabNames(TheCabinets) Call doc.ReplaceItemValue("CWC_CabinetsList", cablist) Call uiDoc.Reload() Call uiDoc.Refresh(False) ' leave all global objects open - will close in queryclose event End Sub _______________________________________________________________ Script Library Functions: Function GetLibraryViaNotes (theAPI As Variant, libsvrnm As String, libpath As String, userpwd As String) As Variant ' retrieves library api object (and returns if successful) Dim uripath As String Dim masterflg As String ' test for master after library get On Error Goto FErrorHandler ' assemble URI and open library libpath = ReplaceSlashes(libpath) uripath = "notes://" & libsvrnm + "!!" & libpath Call theApi.SetNotesLogin(userpwd) Set GetLibraryViaNotes = theApi.GetLibrary(uripath) ' verify we really have opened it (cannot know until you access a property) On Error Resume Next Err=0 masterflg = GetLibraryViaNotes.MasterServer If Err>0 Then ' we didn't really open it... Set getLibraryViaNotes = Nothing Err = 0 ' Reset error code End If Exit Function FErrorHandler: Set GetLibraryViaNotes = Nothing Exit Function End Function Function GetBinderByName(theBinders As Variant, bindertitle As String) As Variant ' retrieves binder by title ' if binder does not exist, call returns error rather than nothing (which is why this function is necessary) On Error Goto FErrorHandler ' get binder Set GetBinderByName=theBinders.ItemByTitle(bindertitle) Exit Function FErrorHandler: ' return nothing Set GetBinderByName=Nothing Exit Function End Function Function ReplaceSlashes (sPath As String) As String '*************************************************************************************************** '* The following subroutine replaces all slashes (\) in the filename with a '/'. '*************************************************************************************************** Do While Instr(sPath,"\") > 0 sPath = Left$(sPath, Instr(sPath,"\")-1) + "/" + Right$(sPath,Len(sPath)-Instr(sPath,"\")) Loop ReplaceSlashes=sPath End Function Function NotesNameReformat(origname As String, formatchoice As Integer) As String ' this function takes an incoming name, sets it to a new Notes Name object ' returns the desired format of the name using the following: ' 1 = canonical ' 2 = abbreviated ' 3 = common only ' ... (see select case for rest) Dim aName As NotesName ' name object On Error Goto FErrorHandler ' create object Set aName = New NotesName(origname) ' process return If (aName.IsHierarchical) Then ' process hierarchical options Select Case formatchoice Case 1 ' canonical NotesNameReformat = aName.Canonical Case 2 ' abbreviated NotesNameReformat = aName.Abbreviated Case 3 ' common NotesNameReformat = aName.Common Case 4 ' organization (O part) NotesNameReformat = aName.Organization Case 5 ' organization unit first level (OU1 part) NotesNameReformat = aName.OrgUnit1 Case 6 ' organization unit second level (OU2 part) NotesNameReformat = aName.OrgUnit2 Case 7 ' organization unit third level (OU3 part) NotesNameReformat = aName.OrgUnit3 Case 8 ' organization unit fourth level (OU4 part) NotesNameReformat = aName.OrgUnit4 Case Else ' return original NotesNameReformat = origname End Select Else ' process flat or internet format Select Case formatchoice Case 11 ' internet address (e.g. jdoe@mw.com) NotesNameReformat = aName.Addr821 Case 12 ' internet address phrase part (e.g. "Jane Doe" part of "Jane Doe" ) NotesNameReformat = aName.Addr822Phrase Case 13 ' internet address localpart (e.g. jdoe part of "Jane Doe" ) NotesNameReformat = aName.Addr822LocalPart Case 14 ' internet address first comment (e.g. My title comments part of "Jane Doe" (My title comments) ) NotesNameReformat = aName.Addr822Comment1 Case Else ' return original NotesNameReformat = origname End Select End If Exit Function FErrorHandler: ' return original input and cancel NotesNameReformat = origname Exit Function End Function