• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

Followup Question to Previous Post

Greetings all,

The post i question, http://www.experts-exchange.com/Applications/Email/Lotus_Notes_Domino/Q_21921926.html, where I ask about sequential numbering.

I started thinking (how dangerous!) about marilyng's cautions about checking for duplicate numbers and how lucky I was that I wouldn't have to do so since the application is only on one server. But the more I thought about it, the more I thought that perhaps there just maybe the chance that 2 people may be composing a work request at almost the same millisecond and that my code would duplicate a work request number. Do you think it's a good idea to check that the work request number exists before being assigned to the work request. And, if so, would my additional code below work?

      Set db = session.CurrentDatabase
      Dim view As NotesView
      Set view = db.GetView( "vAllNum" )                         'this view sorted by num, descending
      Set doc= view.GetFirstDocument                         'yep, it exists
      Do Until Typename(doc.TicketNumber(0)) <> "STRING"      'chk for blank ticket num
            Set doc=view.GetNextDocument(doc)            'if blank go get next doc
            Loop                              'break out of loop, valid ticket num
            acount = doc.TicketNumber(0) + 1            'increment ticket number
            'check that this ticket number does not exist (just in case another ticket was created at almost the same time
            Dim chkdoc As NotesDocument
            Set chkdoc = view.GetDocumentByKey(acount, True) 'try to get doc w/same ticket num
            Do While Not (chkdoc Is Nothing)      'if doc exists
                  acount = doc.TicketNumber(0) + 1      'increment ticket number
                  Set chkdoc = view.GetDocumentByKey(acount, True)      'and check again
                  Loop                  'break out of loop if doc does not exist
                  note.TicketNumber = acount

Thank you.
  • 3
  • 2
  • 2
  • +1
2 Solutions
I'll probably get some stick for this, but the way I get around this by putting a formula into the Postopen event on the form e.g:


This way as soon as a new document is created the next sequential number is taken.

Hope this helps!
Postopen<< the problem with this is that it takes the next number and if the user cancels or tries to exit, then the next number  is gone and you have a skip in number.  So, you'd have to trap the "reserved" number.  Then you have those problems where the user reserves the number for a whole day.. they leave the form open and then go off to lunch or a meeting.  

User A opens document- reserves 123 number
User B opens and saves 124
User C opens and saves 125
User A returns and cancels 123... do you put 123 back into use?  Do you log that you skipped it?  With Sarbanes and Oxley, you can't skip numbers in a proprietary application.  (Course if you're not in USA, then Sarbanes-Oxley law doesn't come into play, however accountants might have questions)

See here: http://www-10.lotus.com/ldd/46dom.nsf/7e6c7e584a76331b85256a46006f083e/1c653d514d1db0ae852569620057ef1f?OpenDocument
for FAQ of FAQs and scroll down to Sequential Numbering...the article: http://www-128.ibm.com/developerworks/lotus/library/ls-sequential_numbers/

I'm sure there are quick and dirty let's-number-these solutions that seem to work, and I have inherited them all at one time or another long after the quick-and-dirty developer left for greener pastures.  So, if you don't plan on being there long enough to see why you shouldn't use a Q&D solution, go ahead, and leave the mess that will eventually result to the next person.

Usually, a document is numbered in some way to keep it from being copied incorrectly in another place.  i.e. I hand you a contract, 123.. then write another 124 and forge your signature to it.  Without some unique document ID or NUMBER,(and tracking) Boss has no way of knowing that I gave the customer 123, but filed 124.

Thems my 2 cents.  And in US Corporations, you have to be able to document sequential numbers and account for them all.  ('tis law now)
Whoops.. forgot to mention, notesrookie, congratulations!! YOU ARE the person who inherited a Q&D solution.  Welcome to the club.:)
and most people pooh-pooh me about this topic.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Sjef BosmanGroupware ConsultantCommented:
Sjef BosmanGroupware ConsultantCommented:
About duplicates and preventing them: very difficult, if not impossible. If you start talking about milliseconds, there will always be a short time that someone can interfere with your operation. Unless, you have some primitive operation (sequence of code unbreakable by a user process) that will allow you to protect a critical section, i.e. you block others, do your "thing" and unblock them again. AFAIK there are some algorithms that support semaphores (those blocks) but I think they aren't required.

The following can be easily implemented:
- put one document in your database that's never referenced
- use Lock and Unlock on that document around your critical section of code

- it is indeed possible that duplicate codes are generated
- if Notes-code is reusable/reentrant, the likelihood would still be small
- develop that Lock-code when it becomes necessary, but make a note somewhere (for your successor)
notesrookieAuthor Commented:
Yes, I know I inherited a Q&D database. Isn't that always the case? marilyng, thanks for the FAQs os FAQs. Great as reference for a whole bunch of other things. And I don't know how long I'll be here

And, sjef, i like your idea about the lock and unlock non-referenced document. I could just do a check for whether that doc is unlocked before assigning the work request number.

Thanks for the great suggestions.

I'm in the UK, and SOX does come into play.
Personally I don't give users the ability to delete documents, so in your scenario:

User A opens document- reserves 123 number
User B opens and saves 124
User C opens and saves 125
User A returns and cancels 123... This will still have been saved as a document with the person's name, reason for cancelling (if applicable) etc.

True it's not the perfect solution, but its a working one ;)
Depends on your application and environment of course.
that would be true, and a good example!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now