Home > Domino Tips > Developer > QuickTips > Creating sequence numbers
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

QUICKTIPS

Creating sequence numbers


Amit Ashar
11.07.2003
Rating: -1.75- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


VIEW MEMBER FEEDACK TO THIS TIP

When creating a workflow application, there is a need to create unique numbers. For example, consider a form that is used to create numbers. You may want to create a unique number, and each time you create a new number, you would want this number to be incremented to show the next number.

  • Create a form, "formNumber" and add a field in it, "fieldNumb."
  • Make this field a "computed when composed field."
  • Create a view (could be hidden), "viewNumber" based on the form "formNumber."
  • This view should have "fieldNumb" as the first sorted column.
  • Now write the following code in the value for that computed field "fieldNumb."
NumberValue := @Subset(@DbColumn
("NOTES":"NOCACHE";"";"viewNumber";1); -1);
@If(@Elements(NumberValue) 
< 1;1;NumberValue + 1)
@DbColumn -- Looks up and returns an entire column of values from a view or folder in either the active database or another Notes/Domino database.

Out of these range of values, you need to pick up the last value -- as you have already sorted the view by the first column. This is done using @Subset and using -1 to search from right to left (if view sorted ascending) and return the first value.

@Elements is used to check if the list has any values, which will happen for the first time. The If function then returns the incremented task number in the computed field.

Always do error handling (as in the above example) whenever you use an @Db function.

MEMBER FEEDBACK TO THIS TIP

This is not a great tip -- if more than one user does the same task at the same time it will generate the same sequence number for multiple documents.
—Mike B.

********************************************************

Just use a specific document (e.g., created with a different form), lock it, update and unlock it! Search the Lotus Domino Designer 6 Help for the string "doc.Lock" for an example in LotusScript.


—Marco C.

********************************************************

Mike B. is correct. This could create a duplicate sequence number. I would modify the original idea.

  1. Create a hidden form (FORM="X") and have two fields:
    • NUMBER/COMPUTED (integer)
    • AUTHORS/EDITABLE/MULTI-VALUE/USE ACL FOR VALUES
    Populate the AUTHORS field with anyone in the ACL who has AUTHOR access. (You don't have to worry about the EDITORS, because they'll be able to modify the document, anyway).

  2. Suppose the sequencing pertains to FORM="MAIN." Put LotusScript in the QuerySave Event of FORM="MAIN" and specify that the code will run only when the document is NEW so that, when a document is created, a lookup is done to the document created with FORM="X," and the existing sequence number is incremented by 1, and DOCUMENT="X" is saved. That way, whenever a document created with FORM="MAIN," the increment takes place. It's also not likely that two people would create a document with FORM="MAIN" at exactly the same second. Even if one document is created one second earlier than another one, the sequence # will still differ.

HOWEVER, this applies if it's a SINGLE-SERVER application! If it's MULTI-SERVER, watch out! Say, on SERVER="A", a document is saved with a particular sequence #, at which time DOCUMENT="X" is incremented by 1. Meanwhile, a document is created on SERVER="B", but replication hasn't taken place, so it's now using the same sequence # used for a document on another server! Of course, since it's a manual process, you can always have the lookup done -- regardless of the server being used -- to the DOCUMENT="X" specified on one particular server.

Not exactly performance friendly, but it's much better for maintaining the integrity of the sequencing.
—Daniel T.

********************************************************

This tip doesn't work in clusters because sometimes a number could be duplicated. Lookups at the same moment won't work. Does anyone know how to solve this problem?

This could be a very good tip.
—Carlos G..

********************************************************

When working in a multi-server environment, there are only two ways to solve this problem, as I see it.

  1. Use a single shared locked document (as suggested by Marco C. above) on a single specific server. When assigning a document number, open it, lock it, locate the highest number, compute and write the newly assigned number, and unlock it.

  2. Write an agent that periodically (say, nightly at 4 a.m.) reviews all documents looking for duplicate numbers. If a duplicate is found, assign the next available sequence number to one of the documents and send a notice to the author and other relevant personnel. I've used this approach with one of my clients and they are quite happy with it.

—Kith N.

********************************************************

This tip will not generate the correct sequence in any workflow application that has a "security in the workflow cycle," since the result of the @DBLookup differs according to the Lotus Notes documents that you are permitted to see.
—Howida E.

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip library by member Amit Ashar. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
QuickTips
View hidden fields on Lotus Notes/Domino forms
A bevy of Notes/Domino development tips
How to protect your Lotus Notes application design
Merging views
Stop an agent without shutting down the Amgr task
Collapsing outlines
How to make Notes view icons run code
Find all databases associated with a template
Verifying user's date setting and time zone on local PC
Load design for a single database

Lotus Notes Domino Formula Language
View hidden fields on Lotus Notes/Domino forms
Case-insensitive @Unique version combines fields on Lotus Notes forms
Do I use Formula or LotusScript to include a doclink to a Notes view?
Top 10 Lotus Notes/Domino coding and development tips of 2008
Provide rich-text formatting via the Profile document and Formula
Top 10 Formula language tips
Using Formula language code to sort Lotus Notes messages by subject
How to create dynamic JavaScript in Notes Domino without formulas
Stop response documents from showing in a Lotus Notes form
Formula language button manages Deny Access list searches

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts