Autor Thema: Real time numbering documents on both WEB and Notes Client  (Gelesen 5573 mal)

Offline Toma Bogdan

  • Aktives Mitglied
  • ***
  • Beiträge: 146
  • Geschlecht: Männlich
  • That's me ...
    • A nice site !
I have a situation where I need to number automatically the documents on Notes and also on the WEB.
For the Notes Client I use script that lock a file which contains the current number
Code
 Sub Initialize
  file% = Freefile
  Open "c:\\seqnum.bin" For Binary Access Read Write Lock Read As file%
   ' You can also use Open "\\NotesServer\SharedDirectory\seqnum.bin"
   ' if your client and server are Win95 or NT based.  Open can take
   ' a UNC path
  Get #file%, 1, SeqNum%
  SeqNum% = SeqNum% + 1
  Put #file%, 1, SeqNum%
  Close file%
  End Sub

This solution generate real time sequential number but it isn't very good because all users needs to have write right on the file system server (on a folder from the server)  :'(

For the Web I use a simple method:
Code
sub initialize
Dim session As New notessession
Dim db As notesdatabase
Dim doc As notesdocument
Dim backdoc As notesdocument
Dim view As notesview

Set doc = session.documentcontext
Set db=session.currentdatabase
Set view=db.getview("RequestID")
Set backdoc=view.getfirstdocument
If Not backdoc Is Nothing Then
LastID = backdoc.requestID(0)
Else
LastID = 0
End If

If LastID <> "" Then
NextID = LastID + 1
Else
NextID = 1
End If
FormattedID = Trim(Str(NextID))
' pad the ID to be 6 characters, with leading zeros
For x% = 1 To (6 - Len(FormattedID))
FormattedID = "0" + FormattedID 
Next

doc.replaceItemValue("Requestid", FormattedID);
End sub 
but when 2 or more users try to create docs inthe same method I will get duplicate numbers ....

Each of these records records needs to be assigned a unique, seven-digit number. The number needs to be assigned when the record is intially saved and never changed after that. Records normally stay on the database only 45-60 days, so a rolling number should not cause problems.

The system currently uses and algorithm based on the current date and time to calculate a value, but we are getting duplicates because Notes time can only go to seconds. Two records added in the same functional area in a one second window are assigned the same number. Even if milliseconds were available it would not help since that would return a value greater than 7 digits and we are limited to that size based on external systems fed from our application.

Some options ... The database includes user profile documents and we suggested adding a counter to that record, but it is concerned about sharing names & passwords. The system needs to work even if two people use the same sign-on.

Is there any way to access an external file (ODBC or sequential) with calls from Notes and guarantee unique sequential numbers? I do not have Notes Pump and prefer not to use Lotus Script connections to ODBC because of response concerns. Any directions or suggestions would be appreciated.
« Letzte Änderung: 04.06.03 - 09:59:27 von Toma Bogdan »

Offline Rob Green

  • Freund des Hauses!
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 2.651
  • Geschlecht: Männlich
    • Meipor
Re:Real time numbering documents on both WEB and Notes Client
« Antwort #1 am: 04.06.03 - 10:07:42 »
you could use on the Webclient an agent locking function:
Declarations
Dim Lock_ID as integer
...

Sub Intialize()
Lock_ID = CreateLock("number") 'generate Lock Object
call sequential_numbering() 'call sub
End Sub

Sub sequential_numbering() 'can only run if the Lock Object is free
Dim checklock as Variant 'to check status of Lock Object
checklock = CodeLock(Lock_ID) 'try to get a free Lock Object
While checklock = False 'if Lock Object is in use
Sleep(3) 'wait 3 seconds
checklock = CodeLock(Lock_ID) 'try it again so long until Lock Object is free
Wend
...
'now set the number if checklock is true
...
checklock = UnLockCode(number) 'free Lock Object, so parallel, same agents can run
End Sub

Sub Terminate()
Lock_ID = DestroyLock(Lock_ID) 'destroy Lock Object
End Sub


Or switch to R6, which embeds locking features finally.

Or you could use the function @Unique without a parameter!
Vielleicht verdirbt Geld wirklich den Charakter.
Auf keinen Fall aber macht Mangel an Geld ihn besser.
(John Steinbeck)

Meiporblog: http://www.meipor.de/blog
allg. Unternehmerblog: http://www.m-e-x.de/blog

Offline Toma Bogdan

  • Aktives Mitglied
  • ***
  • Beiträge: 146
  • Geschlecht: Männlich
  • That's me ...
    • A nice site !
Re:Real time numbering documents on both WEB and Notes Client
« Antwort #2 am: 04.06.03 - 11:11:03 »
should I use this method also on the Notes Client ?

the function @Unique works efficient on the web regarding avoid duplicate numbers ?

Offline Rob Green

  • Freund des Hauses!
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 2.651
  • Geschlecht: Männlich
    • Meipor
Re:Real time numbering documents on both WEB and Notes Client
« Antwort #3 am: 04.06.03 - 11:40:41 »
the above mentioned locking method just applies to the web interface. The Notes client cant use one and the same process since the process is triggered on each client and not on the server, as the Domino server does handle HTTP requests (agent calls !!!) by users centrally.

The unique number is declared by the Notes help to be unique but i would consider a quick scan of the LDD boards to be sure.
Vielleicht verdirbt Geld wirklich den Charakter.
Auf keinen Fall aber macht Mangel an Geld ihn besser.
(John Steinbeck)

Meiporblog: http://www.meipor.de/blog
allg. Unternehmerblog: http://www.m-e-x.de/blog

Offline Toma Bogdan

  • Aktives Mitglied
  • ***
  • Beiträge: 146
  • Geschlecht: Männlich
  • That's me ...
    • A nice site !
just a web method ?
« Antwort #4 am: 04.06.03 - 11:46:43 »
This method works only for the web or I can implement this for the Notes Client too ?


I completed the code as below (it seems that works ok - anybody has a tools to test it as concurential access simulation ?):

Declarations
Dim Lock_ID As Integer

Sub initialize
   Lock_ID = Createlock("number") 'generate Lock Object
   Call sequential_numbering() 'call sub
End Sub

Sub Terminate
   Lock_ID = Destroylock(Lock_ID) 'destroy Lock Object
End Sub

Sub sequential_numbering() 'can only run if the Lock Object is free
   Dim checklock As Variant 'to check status of Lock Object
   checklock = Codelock(Lock_ID) 'try to get a free Lock Object
   While checklock = False 'if Lock Object is in use
      Sleep(3) 'wait 3 seconds
      checklock = Codelock(Lock_ID) 'try it again so long until Lock Object is free
   Wend

' start number proc
'------------------------------------------   
   Dim session As New notessession
   Dim db As notesdatabase
   Dim doc As notesdocument
   Dim backdoc As notesdocument
   Dim view As notesview
   
   Set db=session.currentdatabase
   Set doc = session.documentcontext
   Set view=db.getview("Number")
   Set backdoc=view.getfirstdocument
   
   
   
   If Not backdoc Is Nothing Then
      LastID = backdoc.requestID(0)
   Else
      LastID = 0
   End If
   
   If LastID <> "" Then
      NextID = LastID + 1
   Else
      NextID = 1
   End If
   
   FormattedID = Trim(Str(NextID))
' pad the ID to be 6 characters, with leading zeros
   For x% = 1 To (6 - Len(FormattedID))
      FormattedID = "0" + FormattedID
   Next
   Call doc.replaceItemValue("Requestid", FormattedID)
'------------------------------------------   
' end number proc
   
   checklock = Codeunlock(number)
End Sub

Offline Rob Green

  • Freund des Hauses!
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 2.651
  • Geschlecht: Männlich
    • Meipor
Re:Real time numbering documents on both WEB and Notes Client
« Antwort #5 am: 04.06.03 - 12:27:11 »
Bogdan, beware, the locking mechanism only applies to the Web and NOT to the Notes Client. There is simply no process locking function in R5 !!! Your way by using a file is hereby the best and i wouldnt change it, since you can use it for the Web too, or was there a special reason you deny this solution here?

Read this please: http://www-10.lotus.com/ldd/today.nsf/62f62847467a8f78052568a80055b380/74bd0cdadb2602c385256b56001c0517?OpenDocument&Highlight=0,unique#Preparing%20an%20application%20for%20sequ


and Julie from IRIS:
Lets listen to Julie Kadashevich from IRIS:
Lock functions are currently supported for web agents
(unrelated to any hardware configurations), they are
not supported in Notes server-based agents (such as
scheduled agents).

The reason for that that the locks are effective within
the same PROCESS (such as a web server). And if one understands
the architecture of the scheduled agents, they are not always
within the same PROCESS. So it is unrelated to the mutilple processors
on the server.

By the way, this is probably obvious, but just stating it for
completeness, if you happen to use the same lock in two applications
than do not run in the same process - then nothing will happen (i.e.
no lock, no hang, no data protection). It is a NOOP.

Julie - iris

« Letzte Änderung: 04.06.03 - 12:28:43 von Rob Green »
Vielleicht verdirbt Geld wirklich den Charakter.
Auf keinen Fall aber macht Mangel an Geld ihn besser.
(John Steinbeck)

Meiporblog: http://www.meipor.de/blog
allg. Unternehmerblog: http://www.m-e-x.de/blog

Offline Toma Bogdan

  • Aktives Mitglied
  • ***
  • Beiträge: 146
  • Geschlecht: Männlich
  • That's me ...
    • A nice site !
Re:just a web method ?
« Antwort #6 am: 04.06.03 - 13:09:05 »
Bogdan, beware, the locking mechanism only applies to the Web and NOT to the Notes Client.
I understood ...

Your way by using a file is hereby the best and i wouldnt change it, since you can use it for the Web too, or was there a special reason you deny this solution here?

did you reffer at as I wrote ?
For the Notes Client I use script that lock a file which contains the current number
Code
 Sub Initialize
  file% = Freefile
  Open "c:\\seqnum.bin" For Binary Access Read Write Lock Read As file%
   ' You can also use Open "\\NotesServer\SharedDirectory\seqnum.bin"
   ' if your client and server are Win95 or NT based.  Open can take
   ' a UNC path
  Get #file%, 1, SeqNum%
  SeqNum% = SeqNum% + 1
  Put #file%, 1, SeqNum%
  Close file%
  End Sub

I explain above:
This solution generate real time sequential number but it isn't very good because all users needs to have write right on the file system server (on a folder from the server)

And also this method isn't applicable on a Unix system (in case you didn't use Samba for mapping the specific folder)

So I don't want to depends for another ex-Notes db file (in this case the file seqnum.bin) ... and another reason is that somebody can modify the value from this file with a little effort....

Offline Rob Green

  • Freund des Hauses!
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 2.651
  • Geschlecht: Männlich
    • Meipor
Re:Real time numbering documents on both WEB and Notes Client
« Antwort #7 am: 04.06.03 - 13:38:58 »
the writing right should be applied to a runon server agent and not a user triggered agent. So the server has the right to write. Could this be a way?

The problems are mentioned hereby already.

So you can try to use @unique in both worlds: Notes and Web.
« Letzte Änderung: 04.06.03 - 13:39:53 von Rob Green »
Vielleicht verdirbt Geld wirklich den Charakter.
Auf keinen Fall aber macht Mangel an Geld ihn besser.
(John Steinbeck)

Meiporblog: http://www.meipor.de/blog
allg. Unternehmerblog: http://www.m-e-x.de/blog

Offline Toma Bogdan

  • Aktives Mitglied
  • ***
  • Beiträge: 146
  • Geschlecht: Männlich
  • That's me ...
    • A nice site !
Re:Real time numbering documents on both WEB and Notes Client
« Antwort #8 am: 04.06.03 - 14:25:43 »
The writing right should be applied to a runon server agent and not a user triggered agent. So the server has the right to write. Could this be a way?

Do you talk about the Notes or the Web version ? Because the Web version that I wrote entirely below it seems that works all right ...
For the Notes version I can't use a runon server agent because I need to get a number when a user save a new doc into database.

So you can try to use @unique in both worlds: Notes and Web.

Do you have an example of using @Unique for this problem (REAL TIME sequential number) ?

Offline Rob Green

  • Freund des Hauses!
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 2.651
  • Geschlecht: Männlich
    • Meipor
Re:Real time numbering documents on both WEB and Notes Client
« Antwort #9 am: 04.06.03 - 14:32:53 »
@unique is not a sequential number, its a random number, see the help please  ;)

So the user needs the number immidiately? Where is there a problem with a runonserver agent? You can run the agent, wait until its finished and get the number visually back for the user.
See below the bold line:
"If agent.RunOnServer(doc.NoteID) = 0 Then"
Thats the user trigger mechanism. If the numbering process is finished you can reload your doc and get hereby the number for the user.

See the help:
This agent runs the agent named "Agent to be run parameter LotusScript," passing it the note ID of a newly created document.
Sub Initialize
  Dim s As New NotesSession
  Dim db As NotesDatabase
  Dim doc As NotesDocument
  Dim agent As NotesAgent
  Set db = s.CurrentDatabase
  REM Create document containing data to be passed
  Set doc = New NotesDocument(db)
  doc.TriggerUserName = s.UserName
  Call doc.Save(True, False)
  REM Start agent and pass note ID of document
  Set agent = _
  db.GetAgent("Agent to be run parameter LotusScript")
  If agent.RunOnServer(doc.NoteID) = 0 Then
    Messagebox "Agent ran",, "Success"
  Else
    Messagebox "Agent did not run",, "Failure"
  End If
End Sub
This is "Agent to be run parameter LotusScript." It accesses the passed note ID through ParameterDocID, accesses the referenced document, and removes it.
Sub Initialize
  Dim s As New NotesSession
  Dim agent As NotesAgent
  Set agent = s.CurrentAgent
  Dim db As NotesDatabase
  Dim doc As NotesDocument
  Set db = s.CurrentDatabase
  REM Get document used for passing data
  Set doc = db.GetDocumentByID(agent.ParameterDocID)
  REM Send mail containing passed data
  Dim memo As New NotesDocument(db)
  memo.Form = "Memo"
  memo.SendTo = s.UserName
  memo.Subject = "Message from LotusScript agent"
  memo.Body = "The agent was started by " _
  & doc.TriggerUserName(0)
  Call memo.Send(False)
  REM Delete document used for passing data
  Call doc.Remove(True)
End Sub

Hey, Bogdan, you dont like the Help DB, eh?  ;D ;D
« Letzte Änderung: 04.06.03 - 14:33:54 von Rob Green »
Vielleicht verdirbt Geld wirklich den Charakter.
Auf keinen Fall aber macht Mangel an Geld ihn besser.
(John Steinbeck)

Meiporblog: http://www.meipor.de/blog
allg. Unternehmerblog: http://www.m-e-x.de/blog

Offline Toma Bogdan

  • Aktives Mitglied
  • ***
  • Beiträge: 146
  • Geschlecht: Männlich
  • That's me ...
    • A nice site !
Re:Real time numbering documents on both WEB and Notes Client
« Antwort #10 am: 05.06.03 - 08:11:09 »
@unique is not a sequential number, its a random number, see the help please  ;)
Hey, Bogdan, you dont like the Help DB, eh?  ;D ;D

I like and I read the Help but in this problem the help doesn't help me .... eventually this Notes forum and LDD forum  ::)

----------------

I use the agents that you wrote (the first as action of a form button) but I can't receive any mail message when I push the button... it seems that the second agent doesn't run even I receive the message Agent ran ... so how can help me these agents ?

The normal proc for generating doc number is (it works welll when the users doesn't work simultaneously - doesn't try to save the docs in the same time) :

Sub Querysave(Source As Notesuidocument, Continue As Variant)

   Dim session As New notessession
   Dim db As notesdatabase
   Dim doc As notesdocument
   Dim backdoc As notesdocument
   Dim view As notesview
   
   Set db=session.currentdatabase   
   Set doc=Source .document
   Set view=db.getview("NumberLotus")
   Set backdoc=view.getfirstdocument
      
   If Not backdoc Is Nothing Then
      LastID = backdoc.requestIDLotus(0)
   Else
      LastID = 0
   End If
   
   If LastID <> "" Then
      NextID = LastID + 1
   Else
      NextID = 1
   End If
   
   FormattedID = Trim(Str(NextID))
' pad the ID to be 6 characters, with leading zeros
   For x% = 1 To (6 - Len(FormattedID))
      FormattedID = "0" + FormattedID
   Next
   Call doc.replaceItemValue("RequestidLotus", FormattedID)
   
End Sub
« Letzte Änderung: 05.06.03 - 08:12:27 von Toma Bogdan »

Offline Toma Bogdan

  • Aktives Mitglied
  • ***
  • Beiträge: 146
  • Geschlecht: Männlich
  • That's me ...
    • A nice site !
Re:Real time numbering documents on both WEB and Notes Client
« Antwort #11 am: 15.01.04 - 14:21:36 »
something new ?

 

Impressum Atnotes.de  -  Powered by Syslords Solutions  -  Datenschutz