Solved

Followup Question to Previous Post

Posted on 2006-07-19
8
218 Views
Last Modified: 2013-12-18
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.
0
Comment
Question by:notesrookie
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 21

Expert Comment

by:shuboarder
ID: 17138855
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:

@If(@IsNewDoc;
@Command([FileSave]);
@Command([ViewRefreshFields]))

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

Hope this helps!
0
 
LVL 18

Assisted Solution

by:marilyng
marilyng earned 25 total points
ID: 17139544
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)
0
 
LVL 18

Expert Comment

by:marilyng
ID: 17139570
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.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17139802
Pooh-pooh...
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 100 total points
ID: 17139915
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

Conclusion:
- 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)
0
 

Author Comment

by:notesrookie
ID: 17140747
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.
0
 
LVL 21

Expert Comment

by:shuboarder
ID: 17144750
Marilyng,

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.
0
 
LVL 18

Expert Comment

by:marilyng
ID: 17146052
that would be true, and a good example!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question