« Breakcore Kid | Main| Today we saved about 6000 times 12 MB which is about 60.000 € savings in emc² space. »

Clearing the Replication History Using LotusScript

Tags: development LotusScript

Let's assume we have a Notes database with documents containing reader fields. Let's also assume the reader fields contain group names. If a user has a local replica of this application it will obviously only contain the documents he is allowed to see.

When the admin adds the user to a group which allows the user see more documents in the database they might not replicate down because their modification date is prior to the last replication date stored in the replication history. In order to make these documents replicate to the user they either need to be modified (which would lead to all users replicating them as well) or the replication history of the local replica needs to be cleared.

The code in this entry is a sample to clear the replication history of the current database. It is sample code and hence does not contain error handling etc. and is provided as is - use at your own risk. The code is heavily based on an entry by Paul Ray in the Notes/Domino 4 and 5 Forum which contains the code to display the replication history of a database.

Sample Code

You can download the sample code here...

... or view it below (formatted using Julian's neat tool):

Option Declare ' Notes API constants Const MAXPATH=256 ' Notes API declares Declare Sub OSPathNetConstruct Lib "nnotes" (Byval portName$, Byval ServerName$, Byval FileName$, Byval retPathName$) Declare Function NSFDbClearReplHistory% Lib "nnotes" (Byval hDb&, Byval Flags&) Declare Function NSFDbOpen% Lib "nnotes" (Byval PathName$, hDB&) Declare Function NSFDbClose% Lib "nnotes" (Byval hDB&) Declare Function OSLoadString% Lib "nnotes" (Byval hModule&, Byval StringCode%, Byval retBuffer$, BufferLength%) Function ClearReplHistory(db As NotesDatabase) As Integer '/** ' * This function clears the replication history for a database. ' * @param db (NotesDatabase) - [Input] Indicates the database you wish to open ' * @return The function itself returns an integer. If no errors are found, it returns a 0. Otherwise, it returns the error code returned by the Notes API. ' * This Code is based on Paul Ray's code to read the replication history in the Notes/Domino 4/5 Forum at ' * http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/f7d286be5182a2b3852569f10069c3aa!OpenDocument. ' * @version 1.0 build 20.03.2009 ' * @author Jens Polster (jens.polster@sp-integration.de), SP Integration GmbH ' */ Dim hDb&, hLock&, hSummary& Dim nRetCode% Dim sPath$, sFileName$ ' what to return if no errors are found ClearReplHistory=0 ' prepare a string for API call sPath$=Space(MAXPATH) ' create an API-friendly path to the db and open it OSPathNetConstruct "", db.Server, db.FilePath, sPath$ nRetCode%=NSFDbOpen(sPath$, hDb&) If nRetCode% <> 0 Then ClearReplHistory = nRetCode% Else ' clear replication history nRetCode%=NSFDbClearReplHistory(hDb&, 0) If nRetCode% <> 0 Then ClearReplHistory = nRetCode% Else ClearReplHistory = 0 End If ' free any open handles to the history summary and/or the db If hDb& <> 0 Then NSFDbClose hDb& End If End Function Sub Click(Source As Button) '/** ' * This sample button calls the ClearReplHistory function which clears the database's replication history. ' * If errors were encountered by the Notes API calls in ClearReplHistory, the ' * OSLoadString API is used to determine the error string returned. ' * This Code is based on Paul Ray's code to read the replication history in the Notes/Domino 4/5 Forum at ' * http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/f7d286be5182a2b3852569f10069c3aa!OpenDocument. ' * @version 1.0 build 20.03.2009 ' * @author Jens Polster (jens.polster@sp-integration.de), SP Integration GmbH ' */ Dim session As New NotesSession Dim db As NotesDatabase Dim nReturn% Dim sBuffer$ Set db=session.CurrentDatabase If Msgbox("Do you really want to clear the replication history of " & db.Title & "?", 4+32, "Clear Replication History") = 6 Then ' clear the history nReturn%=ClearReplHistory(db) If nReturn% = 0 Then ' no errors - display success message Msgbox "The replication history of " & db.Title & " has been cleared.", 64, "Success" Else ' find out what the error string is from the API sBuffer$=String$(256, 0) OSLoadString 0, nReturn%, sBuffer$, 255 ' errors found Msgbox "Error found in clearing history: " & sBuffer$, 48, "Replication History Error" End If End If End Sub

Comments

Gravatar Image1 - Or you could just use...

Dim session As New NotesSession
session.CurrentDatabase.ReplicationInfo.ClearHistory

2 lines of code instead of 86.

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

Search

Calendar

MiscLinks

We Use Ytria Lotus Notes Tools For Faster Notes Development and Better Domino Administration

Tags

Site Info