Solved

Followup Question to Previous Post

Posted on 2006-07-19
8
214 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
Pooh-pooh...
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
that would be true, and a good example!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now