Setting the Notes Client Replication Formula from Script

Why is it necessary for the database user to have manager access to a local database when setting the replication formula via the NotesReplicationEntry Class? I was hoping to update the replication formula via script in the database postopen event on several hundred remote Notes Clients but my default db ACL is Author so they would get the “You are not authorized to perform that action.” error. Is there any workaround for this? I made sure to check if the user is working locally first and it still bombs. I was hoping ND6 was the solution to this issue… Am I missing something?

Subject: Setting the Notes Client Replication Formula from Script

I would call it a bug. When NotesReplicationEntry was invented, the intention must have been to let people code this kind of thing.In the user interface you can change a replication formula if your access is only Reader. I guess Notes temporarily turns off the “Enforce…” setting in the ACL to allow this.

Subject: RE: Setting the Notes Client Replication Formula from Script

I hope they fix it soon. It is odd that anyone with Reader access in the ACL can manually modify the replication formula but not from script. I prefer to to leave these kind of things to the user. Thanks for the offer, I may take you up on it.

Subject: RE: Setting the Notes Client Replication Formula from Script

This unsupported demo is only for Windows. I tried it with Reader access in R4, R5 and Notes 6 and it seemed to work, but in the past I have had trouble with similar code, so watch out…

Const wAPIModule = “NNOTES” ’ Windows/32

Declare Private Function NIFFindDesignNote Lib wAPIModule Alias “NIFFindDesignNote” _
( Byval hDB As Long, Byval S As String, Byval C As Integer, N As Long) As Integer

Declare Private Function NSFFormulaCompile Lib wAPIModule Alias “NSFFormulaCompile” _
( Byval N As Long, Byval nN As Integer, Byval F As String, Byval nF As Integer, hFL As Long, nFL As Integer _
, eE As Integer, eL As Integer, eC As Integer, eO As Integer, eN As Integer) As Integer
Declare Private Function NSFItemAppend Lib wAPIModule Alias “NSFItemAppend” _
( Byval hNT As Long, Byval F As Integer, Byval N As String, Byval nN As Integer _
, Byval T As Integer, Byval pV As Long, Byval nV As Long) As Integer
Declare Private Function NSFItemAppendTextList Lib wAPIModule Alias “NSFItemAppendTextList” _
( Byval hNT As Long, Byval N As String, Byval V As String, Byval nV As Integer, Byval F As Integer) As Integer
Declare Private Function NSFItemDelete Lib wAPIModule Alias “NSFItemDelete” _
( Byval hNT As Long, Byval N As String, Byval nN As Integer) As Integer
Declare Private Function NSFItemSetText Lib wAPIModule Alias “NSFItemSetText” _
( Byval hNT As Long, Byval N As String, Byval T As String, Byval nT As Integer) As Integer

Declare Private Function NSFNoteCreate Lib wAPIModule Alias “NSFNoteCreate” _
( Byval hDB As Long, hNT As Long) As Integer
Declare Private Function NSFNoteClose Lib wAPIModule Alias “NSFNoteClose” _
( Byval hNT As Long) As Integer
Declare Private Function NSFNoteOpenExtended Lib wAPIModule Alias “NSFNoteOpenExtended” _
( Byval hDB As Long, Byval NoteID As Long, Byval F As Long _
, Byval F1 As Long, Byval F2 As Long, hNT As Long) As Integer
Declare Private Sub NSFNoteSetInfo Lib wAPIModule Alias “NSFNoteSetInfo” _
( Byval hNT As Long, Byval M As Integer, V As Any)
Declare Private Function NSFNoteUpdate Lib wAPIModule Alias “NSFNoteUpdate” _
( Byval hNT As Long, Byval F As Integer) As Integer

Declare Private Function NSFDbClose Lib wAPIModule Alias “NSFDbClose” _
( Byval hDB As Long) As Integer
Declare Private Function NSFDbGenerateOID Lib wAPIModule Alias “NSFDbGenerateOID” _
( Byval hDB As Long, oid As Any) As Integer
Declare Private Function NSFDbOpen Lib wAPIModule Alias “NSFDbOpen” _
( Byval P As String, hDB As Long) As Integer

Declare Private Sub NEMDisplayError Lib “NNOTESWS” Alias “NEMDisplayError” _
( Byval E As Long)

Declare Private Function OSPathNetConstruct Lib wAPIModule Alias “OSPathNetConstruct” _
( Byval P As Long, Byval S As String, Byval F As String, Byval N As String) As Integer
Declare Private Function OSLockObject Lib wAPIModule Alias “OSLockObject” _
( Byval hM As Long) As Long
Declare Private Function OSMemFree Lib wAPIModule Alias “OSMemFree” _
( Byval hM As Long) As Integer
Declare Private Sub OSUnlockObject Lib wAPIModule Alias “OSUnlockObject” _
( Byval hM As Long)

Sub SetReplicationFormula(db As NotesDatabase, replformula$)
Dim session As New NotesSession
n$ = session.UserName

 Dim hDB As Long
 pn$ = Space(1024)
 OSPathNetConstruct 0, db.Server, db.FilePath, pn$
 NSFDbOpen pn$, hDB
 If hDB = 0 Then Exit Sub
 
 Dim rrv As Long
 NIFFindDesignNote hDB, n$, &H0800, rrv
 
 Dim hNT As Long
 If rrv = 0 Then 
      exists = False
      Dim oid(6) As Long          
      NSFNoteCreate hDB, hNT
      NSFDbGenerateOID hDB, oid(0)
      NSFNoteSetInfo hNT, 2, oid(0)
      NSFNoteSetInfo hNT, 3, &H0800
 Else
      exists = True
      NSFNoteOpenExtended hDB, rrv, &H0800, 0, 0, hNT
 End If
 
 If Not hNT = 0 Then
      Dim hF As Long
      s% = NSFFormulaCompile( 0, 0, replformula$, Len(replformula$), hF, nF%, eE%, eL%, eC%, eO%, eN%)
      If Not s% = 0 Then NEMDisplayError s%
      
      If Not hF = 0 Then
           If exists Then NSFItemDelete hNT, "$ReplClassMasks", 15
           NSFItemAppendTextList hNT, "$ReplClassMasks", "2047", 4, 0
           
           If exists Then NSFItemDelete hNT, "$ReplFields", 11
           NSFItemAppendTextList hNT, "$ReplFields", "", 0, 0
           
           If exists Then NSFItemDelete hNT, "$ReplForm", 9
           NSFItemAppendTextList hNT, "$ReplForm", "0", 1, 0
           
           If exists Then NSFItemDelete hNT, "$ReplFormula", 12
           p& = OSLockObject(hF)
           NSFItemAppend hNT, 4, "$ReplFormula", 12, &H0600, p&, Clng(nF%)
           OSUnlockObject hF
           OSMemFree hF
           
           If exists Then NSFItemDelete hNT, "$ReplPrivateFolder", 18
           NSFItemAppendTextList hNT, "$ReplPrivateFolder", "", 0, 0
           
           If exists Then NSFItemDelete hNT, "$ReplSrcServers", 15
           NSFItemAppendTextList hNT, "$ReplSrcServers", "-", 1, 0
           
           NSFItemSetText hNT, "$ReplVersion", "2", 1
           
           If exists Then NSFItemDelete hNT, "$ReplView", 9
           NSFItemAppendTextList hNT, "$ReplView", "", 0, 0
           
           NSFItemSetText hNT, "$TITLE", n$, Len(n$)
           
           s% = NSFNoteUpdate( hNT, 0)
           If Not s% = 0 Then NEMDisplayError s%
      End If
      
      NSFNoteClose hNT
 End If
 
 NSFDbClose hDB

End Sub

Subject: Problem when Setting the Notes Client Replication Formula from Script

Hi Rod Whiteley,I tried above script for Selective replication. I m facing following problems:-

1)for selective replication i have to click on the button twice.(it does not replicate on first click, and when clicked again it will update the replica).

2)It works only once after modification on Button code ( i.e. when i change the button code then this replication works, until i again go to designer and do the change on button )

has any body tried above? if yes than please help me out, whats need to be done??

is there any db setting or Server document setting ??

Thnaks in Advance.

Subject: RE: Setting the Notes Client Replication Formula from Script

This post was very helpful… it neatly gets around the issue of requiring Manager access to local replicas to change replication formulas. Our databases have a consistent ACL so we were stuck until I found this thread! Thanks very much!

Phil

Subject: RE: Setting the Notes Client Replication Formula from Script

Good morning Rod Whiteley very good this I cosay and my if tendras works to me by chance but I cosay to desible or to enable the part of replication setting the one of advanced setting, using replicationEntry it does not work to desible what is agents, Design elements. thanks