Home > Domino Tips > Developer > Domino > Using the open DB dialogue box to get DB paths and RepID
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

DOMINO

Using the open DB dialogue box to get DB paths and RepID


Jeremy Collett
11.03.2003
Rating: -4.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


I have often needed to link databases together while developing applications, but I haven't wanted to hard code any database paths. To get around this, I use profile documents that store the database names and paths. So that the database paths are accurate, I want the database administrator to be able to select the database they want to link, but using a local browser dialogue box is restricted by network permissions. I have come up with the following technique to get the path, server and database names, and RepID using the "database open" dialogue box. This way you can select any database on any Notes server you have access to (your network access does not enter in to it).

There are five easy steps, with the end result being that you can select a database and the profile automatically updates the RepID.

Code

  1. Create a form, containing three fields:
    • HelpDBString
    • HelpDBName (Editable)
    • HelpDBRepID (Computed to itself)

  2. Create an action hotshot, add this formula:
    FIELD HelpDBString := HelpDBString ;
    FIELD HelpDBName := HelpDBName ;
    
    REM" this prompt uses the open 
    dialogue box and returns the selected 
    database as a list (server : path : name)" ;
    
    tmpList := @Prompt([ChooseDatabase];
    "";"";"";"") ;
    tmpServer := @If(@Subset(tmpList; 1) 
    = "" ; "Local" ; @Subset(tmpList; 1)) ;
    tmpPath := @Subset(@Subset
    (tmpList ; 2) ; -1 ) ;
    tmpTitle := @Subset(tmpList ; -1) ;
    
    @If(tmpPath = 1 ; @Return("") ;
    @Do(
      @SetField("HelpDBString" ; 
    tmpServer + "~" + tmpPath + "~" +
     tmpTitle) ;
        @SetField("HelpDBName" ;  tmpPath) ;
          @PostedCommand
    ([ViewRefreshFields])))
    

  3. Create a refresh function, call this function on the exiting of the DBName field. (This is used to delete entries.)
    Function RefreshForm
     
     Dim ws As New NotesUIWorkspace
     Dim uidoc As NotesUIDocument
     
     Set uidoc = ws.CurrentDocument
     Call uidoc.Refresh
     
    End Function
    

  4. Add this to the postrecalc. (This script is used on a form with 9 database.)
    Sub Postrecalc(Source As Notesuidocument)
    '%REM 
     Set profile = Source.Document
     
     Dim prefixarray (1 To 9) As String
    'build an prefix array.
     prefixarray(1) = "CashControl"
     prefixarray(2) = "Contacts"
     prefixarray(3) = "Discussion"
     prefixarray(4) = "Expenses"
     prefixarray(5) = "Help"
     prefixarray(6) = "InterActions"
     prefixarray(7) = "MailShots"
     prefixarray(8) = "Personnel"
     prefixarray(9) = "ProjectControl"
     
     Dim suffixarray (1 To 4) As String
    'build an prefix array.
     suffixarray(1) = "DBString"
     suffixarray(2) = "DBName"
     suffixarray(3) = "DBRepID"
     suffixarray(4) = "DBServer"
     
     For a% = 1 To 9
      tmpName$ = profile.GetItemValue
    (prefixarray(a%) & suffixarray(2))(0)
      If tmpName$ = "" Then
       For b% = 1 To 3 
        Set item =
    profile.GetFirstItem (prefixarray(a%) & suffixarray(b%)) If Not item Is Nothing Then Set item =
    profile.ReplaceItemValue (prefixarray(a%) & suffixarray(b%), "") End If Next Else tmpString$ = profile.GetItemValue (prefixarray(a%) &
    suffixarray(1))(0) If tmpString$ <> "" Then 'explode the database string. detailArray = Explode(tmpString$, "~") 'set the server string. If detailArray(0) = "Local" Then server$ = "" Else server$ = detailArray(0) End If 'get database replica id. Dim db As New NotesDatabase (server$, detailArray(1)) 'get the item from the profile. Set repid =
    profile.GetFirstItem (prefixarray(a%) & suffixarray(3)) 'update the item in the profile. Set repid =
    profile. ReplaceItemValue(prefixarray(a%) & suffixarray(3), db.ReplicaID) End If End If Next '%ENDREM End Sub

  5. Add this function. (This function was found on SearchDomino.com. I did not write it, but it is very useful.)
    Function Explode (Byval wordList 
    As String, sep As String) As Variant
    %REM
    this function explodes a string in to 
    a list given a specified separator.
    %END REM
     
     Dim sepLen As Integer, wordLocation 
    As Integer, wordLen As Integer, 
    subWordLen As Integer
     Dim instanceCount As Integer, i As Integer 
     Dim tmpWordList As String, word As String
     
     SepLen% = Len(Sep$)
     tmpWordList$ = wordList$
     instanceCount% = 0 
     wordLocation% = Instr(tmpWordList$, 
    sep$)
    'set-up a loop whiles the separator 
    excises in the string.
     While wordLocation% > 0
      wordLen% = Len(tmpWordList$)
      subWordLen% = (wordLocation% - 1)
     + sepLen%
      tmpWordList$ = Right(tmpWordList$, 
    wordLen% - subWordLen%)
      wordLocation% = Instr(tmpWordList$, 
    sep$)
      instanceCount% = instanceCount% 
    + 1
     Wend
    'set the return list to equal the amount 
    of separators found.
     Redim returnList(instanceCount%)
     
     wordLocation% = Instr(wordList$, sep$)
    'loop through the original string 
    extracting the list elements.
     For i% = 0 To InstanceCount
    'if no separator can be found exit.
      If wordLocation% = 0 Then
       word$ = wordList
       returnList(i%) = word$
       Exit For
      Else
       word$ = Left(wordList$, 
    (wordLocation% - 1))
      End If
      returnList(i%) = word$
      wordLen% = Len(wordList$)
      subWordLen% = (wordLocation% - 1) 
    + sepLen%
      wordList$ = Right(wordList$, wordLen%
     - subWordLen%)
      wordLocation% = Instr(wordList$, sep$)
     Next i%
    'return the list as a variant 
     Explode = ReturnList
     
    'have a nice day.
     
    End Function
    

Do you have comments on this tip? Let us know.


Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Domino
Mimic Lotus Notes Domino application functionality on the Web
A single form to view and edit any Lotus Notes document
DECS and DCR external data access considerations
How to create non-scrolling Lotus Domino view headers on the Web
Disabling the 'Submit' button on a form
An easier way to update a rich text field
Results from Default Notes Search have # of responses in brackets
Lotus Notes/Domino veteran offers comprehensive list of app dev tools
Notes to XML. . .and back again
Creating thumbnail images using LS2J in LotusScript

Lotus Notes Domino Formula Language
View hidden fields on Lotus Notes/Domino forms
Case-insensitive @Unique version combines fields on Lotus Notes forms
Do I use Formula or LotusScript to include a doclink to a Notes view?
Top 10 Lotus Notes/Domino coding and development tips of 2008
Provide rich-text formatting via the Profile document and Formula
Top 10 Formula language tips
Using Formula language code to sort Lotus Notes messages by subject
How to create dynamic JavaScript in Notes Domino without formulas
Stop response documents from showing in a Lotus Notes form
Formula language button manages Deny Access list searches

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts