One of the great strengths of notes is that users can access the same information on different servers or on local replicas. It can also be a real problem.

I have frequently had calls from people along the lines of

“I added some information and I can see it but my colleague can’t”.

One of our clients recently wanted to deploy replicas of their business critical applications to a different server to improve robustness. Without taking any special steps this actually reduces robustness and user satisfaction because over a period of time users end up using different replicas from each other and sometimes are using a slow server ( a branch office in South Africa on broadband was often a culprit ) without realising this.

The dynamics of how Notes chooses which server to open next often puzzles me but I was once told that it was to do with the alphabetical order of the servers because of the order of the databases in catalog.nsf – and once the top icon is for a distant server users will always use that server.

Anyhow, the code that follows may help. In this particular case the business applications are only used on one site so access to any off-site server should only be required if the on-site server cannot be accessed, his makes it easy – in other projects I have used a rule whereby the application should be accessed on the same server as the persons mail file

There are 3 design elements :

1) an action that creates a profile document listing the name of the preferred server – this is manually triggered when the system is set up

2) some script in the database initialize script which compares the preferred server lists above with the actual server

3) a subform which pops up to alert the user if looks as though they are using the wrong server.

Essentially the code does the following :

checks to see if the person has access to the database
gets the preferred server name from the profile document and compares this with the actual server name.

if the actual server != the preferred server then the system checks to see if the preferred server can be opened.
if the preferred server can be opened then the user is advised as shown in the screen shots below otherwise the user is allowed to open the requested server

I wasn’t able to write code to actually switch to the new database so instead it closes the database and brings the correct icon to the top on the workspace. i have not tried this in a “workspaceless” environment.

Image:SNTT: Stopping users from opening the wrong replica

Image:SNTT: Stopping users from opening the wrong replica

You may think that the steps required to access the “wrong” server are a bit OTT but remember that this pop up only gets triggered when the “preferred” server is available.

Core Code

Sub s_ServerCheck_6_01

‘##############################################################################
‘ Sean cull, www.focul.net, 30/9/08
‘ the purpose of this code is detect the opening of a suboptimal replica and redirect the user to the best replica
‘ this will be tested each time that the database is opened to make sure that the person is opening the most efficient server
‘ other componenets in this functionality are :        
‘sfServerCheck – subform
‘ s_ServerCheck_6_01 ( Database Scripts )
‘AdministrationSet default server ( Agent )

‘##############################################################################

Dim ws As New notesuiworkspace
Dim session As New notessession
Dim db As NotesDatabase
Dim level As Integer
Dim stringStrings As String
Dim profileStrings As notesitem
Dim doc As NotesDocument
Dim currentserver As String
Dim alternatedb As New NotesDatabase( “”, “” )
Dim gooduidb As notesuidatabase
Dim baduidb As notesuidatabase
Dim uidb As NotesUIDatabase
Dim acceptance As Variant
Dim titlestring As String

Set db = session.currentdatabase

If db.server = “” Then
       currentserver = “Local”
Else
       currentserver = db.server
End If

level = db.CurrentAccessLevel

If level < 1 Then ' 1 = depositer
       Print “You do not have access to this database”                
       Exit Sub
End If

Set doc = db.GetProfileDocument(“Default Server”,db.ReplicaID)
If Not doc Is Nothing Then
       Set profileStrings = doc.GetFirstItem(“ProfileStrings”)
       If doc.hasitem(“ProfileStrings”) Then                
               stringStrings doc.profilestrings(0)
               If Not stringstrings = “NONE” Then
                       If Not FoCulCommonName_5_01 (db.server) = FoCulCommonName_5_01 (stringstrings) Then
                               Print “Default server listed as ” & stringstrings & ” but you appear to be on ” & currentserver                                
                       ‘try and open alternate db
                               If alternatedb.OpenByReplicaID( stringstrings, db.ReplicaID) Then
                                       Print( alternatedb.Title & ” was successfully opened” )
                                       Set Doc = New NotesDocument ( db )                                                
                                       doc.recycle_flag_tx = “False”
                                       doc.actualserver_tx = FoCulCommonName_5_01(db.Server)
                                       doc.preferredserver_tx = FoCulCommonName_5_01(stringstrings)
                                       TitleString = “You may be using the wrong server”
                                       
‘                                        flag = notesUIWorkspace.DialogBox
( form$ , [autoHorzFit] , [autoVertFit] , [noCancel] , [noNewFields] , [noFieldUpdate] , [readOnly] , [title$] , [notesDocument] , [sizeToTable] , [noOkCancel] , [okCancelAtBottom] )
                                       Acceptance =  WS.DialogBox( “sfServerCheck” , True , True , True , False , False , False , TitleString , Doc, True , False , True )
                                       
                                       If Not doc.plsContinue_tx(0) = “” Then  ‘ subform negotiated successfully – force this db open
                                               Exit Sub
                                       End If                        
                                       
                                       Print “The preferred database can be opened – switching now”
                                       Set baduidb = ws.CurrentDatabase
                                       
                               ‘Call notesUIWorkspace.OpenDatabase( server$, file$, view$, key$, newInstance, temp )                                        
                                       
                                       ‘ open the preferred database so that the icon is at the top of the icon stack
                                       ‘ then close both ui databases sown
                                       ‘ if anyone has a better method then please let me know !
                                       
                                       Call WS.OpenDatabase( stringstrings, alternatedb.FilePath,””, “”, False, False)                                
                                       Set uidb = ws.CurrentDatabase
                                       Call uidb.Close
                                       Set uidb = ws.CurrentDatabase
                                       Call uidb.Close                                                
                               Else
                                       Print( “Unable to open database – allowing this replica to be used” )
                               End If                                
                       End If
               End If                
       End If
End If
End Sub

You can download a copy of the design elements in a database by clicking the link below. As ever please let me know if there is a better approach !