How to main the sequentially generated numbers for each document when Replication is enabled usin Lotus Script?

Current Scenario is - When a document is created, a number is assigned to that particular document. This is incremented sequentially as and when users created documents on Production. Issue faced, is when Replication is enabled, there is a duplication of these sequentially generated numbers. How do we maintain them unique when Replication is being used? Please help.

A great link! My advice:
- don't rely on sequential numbering in Notes... never!
- look for alternatives
- can you use @Unique to produce a unique key?
- last resort: use system-wide locks (could be a disaster for the performance)

Another option if you need to work with existing numbering and if the numbers don't have to be immediately available:

. Create the document without a number
. Create a view to display documents without numbers, sorted in created order, ascending
. Create a scheduled agent to assign numbers - schedule it to run overnight

We do numbering on multiple db's without problems when using the following setup
- create a profile document for the db, in a field you define a "Main" server
- when a document is created and saved for the first time you check the server and if it is the main calculate or lookup the new number in the querysave of the document
- at night an agent runs on the documents which are not created on the main server to populate the number

Agree with SJef to find alternatives to Sequential numbesr but it seems that some people just love to have them nice and neatly ordered no matter what the designers/admins say :)

Depending on your connectivity to servers and how often new docs are created compared to just edits.

If you are using a field and @dblookup or @DBcolumn then make it pick from a specific server and database rather than null values from current database. also form should save doc immediately once number allocated.
If value/formula is @error then create a local random ID that agent picks up on central server once every x minutes/hours.
Have a check for duplicates and inform an admin once a day etc.

Sort of combining the above into one solution that covers most times they absolutely insist a document is sequential and generally when creating documents is not as heavy as editing etc.

@Sjef - @unique I can propose, but what about the existing documents? As doninja says, people do love sequential numbers!!!

Let me explain you the current working.

A Hidden View is present where action button is available to create a form only to enter a 'Record Number'. The Admin will create the document and enter the value in Record Number (start point for sequential number)

Once creates document completes all data in the form and click on 'Save and Close' - Script Library is called in which one sub function is called to assign the Number. The code for the same is as below:

To retain the code, use RonaldZaal's suggestion, ie add a check for the designated "Main" server and only add numbers for documents on this server. Documents created on other replicas to be processed by a scheduled agent outside normal office hours, on the designated "Main" server, to assign numbers.

@RonaldZaal - Can you please help me how to go about the agent? The Db Profile is already set up and the Number is assigned when user creates the document on Server. At least provide me the logic to it.
@Gingerdeb - Thanks to you too.

Hello,
in the code snippets below you find the code
doc Postopen
function calculate the number
the function called by the agent which runs as server so it sees all documents.
You need to check/change some field names!
Let me know how things workout.

' we use Postopen, you can maybe better use QuerySave in your caseSub Postopen(Source As Notesuidocument)'__ create Ticket NR if possible / needed Dim ticketNr As String Dim doc As notesdocument Dim db As NotesDatabase Dim parameterDoc As NotesDocument Dim homeServer As NotesName Dim currentServer As NotesName Set doc = source.Document Set db = doc.ParentDatabase If doc.IsNewNote Then ' new doc, check home server Set parameterDoc = db.GetProfileDocument("nApplicationProfile") Set homeServer = New NotesName(parameterDoc.GetItemValue("homeServer")(0)) Set currentServer = New NotesName(db.Server) If homeServer.Common = currentServer.Common Then doc.gesaNR = CalcgesaNR(Source) ' get me my number Call source.Refresh End If End If End Sub-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------The function called resides in a script libFunction CalcgesaNR(uidoc As NotesUIDocument) As String'__ function to get next Ticket Nr when user is working on the HomeServer'__called by doc postopen Dim session As New notessession Dim ReturnValue As String Dim intReturnValue As Long Dim tmpDocID As String Dim gesaDB As String Dim NumberRoot As String Dim Separator As String Dim DocType As String Dim DocDomain As String Dim CheckAgent As notesAgent Dim paramdoc As NotesDocument ReturnValue = "" Set CheckAgent=session.currentdatabase.GetAgent("(GetNextDocNumber)") gesaDB=Trim$(uidoc.FieldGetText("gesaDB")) ' you don't need this, it takes a preset value for the numbering to get AAA-0000021, or BBB-0000232 etc Set paramdoc=session.CurrentDatabase.GetProfileDocument( "(GetNumberProfile)" , session.CommonUserName ) Set Paramdoc=GetProfileDoc(paramdoc) Call removeAllItems(paramdoc) Call paramdoc.replaceItemValue("gesaDB",gesaDB) Call paramdoc.replaceItemValue("gesaNR","") Call paramdoc.replaceItemValue("test","before agent") Call paramdoc.Save(True,False) tmpDocID=paramdoc.NoteID' Call TESTDoGetNumberList(tmpDocID) ' For testing of agent Call checkAgent.RunOnServer(tmpDocID) ' Normal call to agent Set paramdoc=Nothing Set paramdoc=session.CurrentDatabase.GetDocumentByID(tmpDocID) Set Paramdoc=GetProfileDoc(paramdoc) intReturnValue=Clng(Paramdoc.GetItemValue("gesaNR")(0))+1 ReturnValue=Cstr(intReturnValue) If Len(Cstr(ReturnValue)) > 6 Then ReturnValue = Right("0000000"+Cstr(ReturnValue),7) Else ReturnValue= Right("000000"+Cstr(ReturnValue),6) End If CalcgesaNR=ReturnValueEnd Function-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------The agent which gets called only has code : call this function. it runs as serverSo in the agent you have :Use "name of scriptlibrary" ran as serverCall DoGetNumbersList()-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Sub DoGetNumbersList()'Called by agent Dim session As New notessession Dim curAgent As notesAgent Dim paramDocID As String Dim paramdoc As NotesDocument Dim viewToSearch As NotesView Dim gesaDB As String Dim Result As String Dim coll As NotesViewEntryCollection Set curAgent=session.CurrentAgent If curAgent Is Nothing Then Exit Sub ParamDocID=curAgent.ParameterDocID Set ParamDoc=session.CurrentDatabase.GetDocumentbyID(ParamDocID) If Paramdoc Is Nothing Then Exit Sub Set ViewToSearch=Session.CurrentDatabase.GetView("gesaNrs") ' This is your all numbers view If ViewToSearch Is Nothing Then Exit Sub gesaDB=paramdoc.GetItemValue("gesaDB")(0) ' this is used to get the prefix used here ' if you don't need a prefix you can remark this out ' if you don't use a prefix you can use here to get the last document in the view ' you have to change the next 3 lines Set coll=ViewToSearch.GetAllEntriesByKey(gesaDB) Dim curEntry As NotesViewEntry Set curEntry=Coll.GetFirstEntry ' it is sorted asc Result = curEntry.ColumnValues(1) ' return first column value Call paramdoc.ReplaceItemValue("gesaNR",Result) ' stock number Call paramdoc.replaceItemValue("test","after agent") ' to test if the agent ran ok Call paramdoc.Save(True,False)End Sub

I may be missing something in the code above, but it looks like you still need a scheduled agent to process those documents without numbers that have been created in other replicas. I don't see anything that's processing a collection of these documents.

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…

Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.

If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you!
In this Micro Tutorial, you'll learn yo…

In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB.
To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…