Solved

Followup Question to Previous Post

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

Expert Comment

by:Sjef Bosman
ID: 17139802
Pooh-pooh...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to add a username for multiple users in Lotus 6 103
Text over two lines in VBA for email 26 159
Switching from Lotus Notes to Outlook 4 46
IBM Lotus Notes Rules not working 5 103
Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
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.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

947 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

20 Experts available now in Live!

Get 1:1 Help Now