PermaLink (Updated) Setting Selective Replication via LotusScript (and C API)06/28/2007 06:36 AM
Update: this technique works in two databases and fails in two others.  I have no idea why.  I think "Enforce Consistent ACL" is being used in all cases.

I spent more time than I'd like this week figuring out how to set a replication formula via the Notes C API (but calling the C API via Lotusscript).  The basics were done for me already, but there were a couple of weird gotchas that made setting a selective replication formula useless till I figured them out.

Here's the summary.  To make the code below work, you need to have your server explicitly in the db's ACL.  Having the server name in a group (such as LocalDomainServers) doesn't seem to work.  Your ID needs to have a minimum of editor access.  NoteDatabase.Replicate(<server>) needs the canonical server name.  If you don't get these details right, you'll see a replication occur, but the selective replication formula won't take effect.

Note:  this is tested on Notes 6.5.4.  I don't think it can work on versions earlier than 6 (NotesReplicationEntry came in with 6).  If you happen to try it on 7 or higher, let me know what happens.

The bulk of this came from a Notes 6/7 forum post, but I could not have made it work without some details from other sources.

Then there's this link which causes problems when put into pass-thru HTML
http://www-1.ibm.com/support/docview.wss?rs=899&context=SWA40&context=SWA50&context=SWA60&context=SWCZ0&context=SWD10&context=SS4R7J&context=SSES8G&context=SSKTYF&context=SSMT72&context=SSPQ7E&context=SSMSB2&context=SS6JVW&context=SS5LUA&context=SSCM2P&context=SS3LP9&context=SSFLMV&context=SSESJN&context=SSKTPA&context=SSVHEW&context=SSVHFY&context=SSVLBW&dc=DB510&dc=DB520&dc=D800&dc=D900&dc=DA900&dc=DA800&dc=DA440&dc=D600&dc=D700&dc=DB540&dc=DB400&dc=DA410&dc=DA450&dc=DA430&dc=DA420&dc=DA460&dc=DB300&dc=DA470&dc=DA480&dc=DB100&dc=DA4A10&dc=DA4A20&dc=DA700&dc=DA4A30&dc=DB550&dc=D100&q1=155542&uid=swg21085595&loc=en_US&cs=UTF-8&lang=all

'Declarations: Const APIModule = "NNOTES" ' Windows Declare Sub keybd_event Lib "user32.dll" (Byval bVk As Integer, Byval bScan As Integer, Byval dwFlags As Integer,Byval dwExtraInfo As Integer) Declare Function OSPathNetConstruct Lib APIModule Alias "OSPathNetConstruct" _ ( Byval NullPort As Long, Byval Server As String, Byval FIle As String, Byval PathNet As String) As Integer Declare Function NSFDbOpen Lib APIModule Alias "NSFDbOpen" _ ( Byval PathName As String, DbHandle As Long) As Integer Declare Function NSFDbClose Lib APIModule Alias "NSFDbClose" _ ( Byval DbHandle As Long) As Integer Declare Function NSFNoteOpen Lib APIModule Alias "NSFNoteOpen" _ ( Byval DbHandle As Long, Byval NoteID As Long, Byval F As Integer, hNT As Long) As Integer Declare Function NSFNoteClose Lib APIModule Alias "NSFNoteClose" _ ( Byval hNT As Long) As Integer Declare Private Function NSFNoteUpdate Lib APIModule Alias "NSFNoteUpdate" _ ( Byval hNT As Long, Byval F As Integer) As Integer Declare Function OSMemFree Lib APIModule Alias "OSMemFree" _ ( Byval Handle As Long) As Integer Declare Function OSLockObject Lib APIModule Alias "OSLockObject" _ ( Byval H As Long) As Long Declare Sub OSUnlockObject Lib APIModule Alias "OSUnlockObject" _ ( Byval H As Long) Declare Private Function NSFItemAppend Lib APIModule Alias "NSFItemAppend" _ ( Byval hNT As Long, Byval F As Integer, Byval N As String, Byval nN As Integer _ , Byval T As Integer, Byval V As Long, Byval nV As Long) As Integer Declare Function NSFItemDelete Lib APIModule Alias "NSFItemDelete" _ ( Byval hNT As Long, Byval N As String, Byval nN As Integer) As Integer Declare Function NSFFormulaCompile Lib APIModule 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 Sub Poke Lib "MSVCRT" Alias "memcpy" _ ( Byval P As Long, S As Any, Byval N As Long) 'Functions: Sub Initialize Dim repl As String Dim workspace As New NotesUIWorkspace Dim db As NotesDatabase Dim db1 As NotesDatabase Dim db2 As NotesDatabase Dim s As New NotesSession Dim uname As NotesName Dim rep As NotesReplication Dim server As String Dim nn As NotesName server = "YourServer/ABCD" Set nn = s.CreateName(server) Set db = workspace.CurrentDatabase.Database Set uname = s.CreateName(s.UserName) 'be sure to put YOUR forumula here, otherwise you'll probably get no documents repl = "Select Form = ""BarCode"" " Call SetReplicationFormula(repl, uname, db) Set rep = db.ReplicationInfo Call rep.ClearHistory() Call rep.Save() Call db.Replicate(nn.Canonical) End Sub 'METHOD FOR SETTING REP FORMULA - expects a valid formula and a notesdatabase object - ' it will then find the rep formula for the current user (uName.canonical) and set the formula. ' This works even when you don't have manager access. Sub SetReplicationFormula(formula As String, uname As NotesName, db As NotesDatabase) Dim nF As Integer Dim p As Long Dim eE As Integer Dim eL As Integer Dim ec As Integer Dim eO As Integer Dim eN As Integer Dim dbFile As String Dim repDetails As NotesReplication Dim repEntry As NotesReplicationEntry Dim nc As NotesNoteCollection Dim noteId As String Dim notenum As Long Dim nextNoteID As String Dim i As Integer Dim repDoc As NotesDocument Dim fp As String ' Dim res As Integer Const ButtonTitle = "Replication Formula" Const itemName = "$ReplFormula" '// Get the replication settings Set repDetails = db.ReplicationInfo '// Get the replication details Set nc = db.CreateNoteCollection(False) nc.SelectReplicationFormulas = True Call nc.BuildCollection '// Step through the found design notes and get teh associated replication entry noteID = nc.GetFirstNoteId For i = 1 To nc.Count Set repDoc = db.GetDocumentByID(noteID) If repDoc.GetItemValue("$TITLE")(0) = uName.Canonical Then Exit For End If noteID = nc.GetNextNoteId(noteID) Next noteNum = Val( "&h" & NoteID) If noteNum < 0 Then noteNum = 65536 + noteNum dbFile$ = String$(1024, " ") ' OSPathNetConstruct 0, "", "oneTeam\Live\" + db.filename, dbFile$ 'Get handle on database fp = db.FilePath ' res = Messagebox(fp, 0 , "filepath") OSPathNetConstruct 0, "", fp, dbFile$ 'Get handle on database Dim hDB As Long NSFDbOpen dbFile$, hDB 'Open the database If hDB = 0 Then Exit Sub Dim hNT As Long NSFNoteOpen hDB, noteNum, 0, hNT 'Open the repFormula Note If Not hNT = 0 Then Dim hF As Long NSFFormulaCompile 0, 0, formula$, Len(formula$), hF, nF%, eE%, eL%, eC%, eO%, eN% If Not hF = 0 Then NSFItemDelete hNT, itemName, Len(itemName) p& = OSLockObject(hF) Poke p& + nF% - 2, &HFFFE, 2 NSFItemAppend hNT, 4, itemName, Len(itemName), &H0600, p&, Clng(nF%) OSUnlockObject hF OSMemFree hF NSFNoteUpdate hNT, 0 End If NSFNoteClose hNT End If NSFDbClose hDB End Sub
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.


Technorati:
This page has been accessed 534 times. .
Comments :v

1. Alain H Romedenne12/08/2007 02:58:08 PM
Homepage: http://opendom.blogspot.com


I tend to suspect your problems most probably relate to mal-formed or ancient replication notes. I would not investigate your code content further.




2. Jurjen van den Broeck06/10/2008 06:37:13 PM


Dear,

I'm looking for the C-API function to create a replication-entry on the repliction page of a database.

Because I'm using a (local) scheduled agent, I'm not allow to use UI like NotesUIWorkspace.

Any help?




Add Manual Trackback
Please enter the details of the trackback post. Your trackback will not appear on the site until it has been verified. This won't be immediate, as trackbacks are validated on a scheduled basis. Be patient.











Powered By :

BlogSphere V1.2 Beta 3

Join The WebLog Revolution at BlogSphere.net

Contact Me
The BlogRoll
What is a Jagular?
It is a malapropism for jaguar found in Winnie the Pooh and has nothing to do with jugulars.

usually

for more information about jagulars try here
Lotus Domino ND6 RSS OPML List RSS News Feed RSS Comments Feed Geo URL netcraft RSS Validator Blog Admin Lotus Geek Chris. A. Brandlehner Open Notes Picture Database OpenNTF CoComment Integrated BlogSphere
Calendar
No calendar found.
By Category
Hot Blogs
No Hot Blogs
Monthly Archive