Subject: Programmatically change replication formula for local databases
We added code to the onLoad event of a form that does it. It’s not elegant but it works. The new replica is created locally, then the start form is opened and closed and the replication formula is now set. Hope this helps.
Sub Onload(Source As Notesuidocument)
Dim servername, sname As String
Dim lpBuff As String * 25
Dim ret As Long
Dim UserName As String
ret = GetUserName(lpBuff, 25)
UserName = Ucase(Left(lpBuff, Instr(lpBuff, Chr(0)) - 1))
servername = source.FieldGetText( “ServerName” )
sname = source.FieldGetText( “ServerName” )
’ get windows user name and the name of the device
Call source.FieldSetText(“textUsername”, UserName)
Set WSHNetwork = CreateObject(“WScript.Network”)
strDomain = WSHNetwork.UserDomain
strUserName = WSHNetwork.UserName
strComputerName = WSHNetwork.ComputerName
Call source.FieldSetText(“textLaptopID”, strComputerName)
source.Refresh
REM set replication formula
’ if the server name is not the central server, it has to be a local replica
If sname = “DevServer” Or sname =“Mail” Or sname = “DomServer” Then
’ Messagebox “exiting sub”, “test”
Exit Sub
Else
dbName$ = source.FieldGetText( “textDbName” )
Dim db As New NotesDatabase(“”, dbName$)
Dim rep As NotesReplication
Dim re As NotesReplicationEntry
If Not db.IsOpen Then
’ Messagebox “No local database”, dbName$
Exit Sub
End If
REM Get source and destination computer
source1$ = “Any Server”
If Instr(1, source1$, “Any Server”, 5) > 0 Then
source1$ = “-”
End If
destination$ = servername
If Instr(1, destination$, “Any Server”, 5) > 0 Then
destination$ = “-”
End If
REM Get replication entry
Set rep = db.ReplicationInfo
Set re = rep.GetEntry(source1$, destination$, False)
Dim f As String
f = re.Formula
Dim positionOfChar As Integer
positionOfChar = Instr(f, strComputerName) = 0
If positionOfChar < 0 Then
’ Messagebox “changing rep formula”, “test”
’ Set formula
re.Formula = “SELECT SubscriberId = '” + strComputerName + “’ | SubscriberId = ‘999’”
Call re.Save
Call Rep.Save
’ Messagebox re.Formula, "Formula for " & source1$ & " and " & destination$
Else
’ Messagebox “NOT changing rep formula”, “test”
End If
End If
exitsub:
End Sub