Solved

Followup Question to Previous Post

Posted on 2006-07-19
8
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

628 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