Programmatically change replication formula for local databases

Dear all,

Is it possible to programmatically change the replication formula of a local database?

(Replication > Options for this Application > Space Savers > Documents that meet a selection formula)

I didn’t find anything within the regular Formula/LS/Java but this should be possible interfacing some existing dll.

They don’t provide source of their dll but managed to package something : Martin Scott Consulting | Replication DLL http://www.martinscott.com/struturo.nsf/id/products_dll

Thanks for any hint!

Subject: to be investigated…

Thanks for the information… Not sure that it’s exactly what I’m looking for but I’ll investigate that next week!

If anyone else knowledgeable is also passing by this thread, feel free to add some more infos :slight_smile:

Regards

[EDIT week+1] IBM C API Notes/Domino 9.0.1 have indeed everything needed, now should just try to make it work directly from LS.

IBM Developer https://www.ibm.com/developerworks/lotus/documentation/capi/

http://www-12.lotus.com/ldd/doc/domino_notes/9.0/api90ug.nsf/85255d56004d2bfd85255b1800631684/80194706d58ab82e85255f58005cae65?OpenDocument http://www-12.lotus.com/ldd/doc/domino_notes/9.0/api90ug.nsf/85255d56004d2bfd85255b1800631684/80194706d58ab82e85255f58005cae65?OpenDocument

Subject: Never tried, but…

The type of note you want is NOTE_CLASS_REPLFORMULA. You can use this in NSFSearch to get all replication formula notes. Within each is a field called $ReplFormula that has the replication formula. There are some other fields that also store things that look like replication formulas (AdvFormula, $HLFormula), but I’m not sure offhand what those do. Hopefully it’s enough to get you started.

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