Q
Problem solve Get help with specific problems with your technologies, process and projects.

Create automatic counter

How do I create an automatic counter or sequential number that will appear in every new document I create when I hit the new button in Domino Designer 6.5?

I have a "document" form and in that there is a field called currentvalue(Number, computed when display)and has the following formula "CurrentValue:=@TextToNumber(@GetProfileField("counter profile";"counter")); @SetProfileField("counter profile";"counter";@Text(CurrentValue +1))"

I also have created a profile form and called it "counter profile." I added one field in this form and called it counter(Number). I then created an agent called "Edit Counter" and added the following formulas "@Command([EditProfile]; "counter profile"); @All" when I try to run the database and hit the new button to create a new document, new document opens and in the currentvalue field the following text appears "@ERROR".

Do you have any suggestions? I appreciate your help.

View member feedback to this Ask the Expert Q&A.

Profile documents should not be used for sequential numbering. Profile documents are great for efficient access to user-specific settings, but they are cached in memory when a user opens a database. This will lead to duplicate numbers being generated. For example, if the last used number was 100 and two users open the database at the same time, then their new documents will both be assigned number 101, because the profile document in memory says that's the next number. It will not be updated in memory until they close the database and re-open it.

Here is a better design:

  1. Create a simple Counter form with a number field that is computed. Also include an authors field that is computed to "*", to ensure that all users have the ability to update the document, even though they won't edit it directly.

  2. Create a hidden lookup view that displays the document. (Make sure that all users have the ability to read the view -- just keep it out of sight.)

  3. When the user clicks the "New" button, trigger LotusScript or formulas to look up the counter document, get the number, put it on the form (in a computed field -- not a display field), and increment the counter document.

MEMBER FEEDBACK TO THIS ASK THE EXPERT Q&A:

I have one additional suggestion for Step 3 in Brad Balassaitis' answer for sequential numbering. I created a sequential numbering method like Brad described a number of years ago, but one problem I had was users getting an occasional duplicate number until I incremented the counter document first before getting the number for the users document. In other words, "get the counter document, increment the counter document, then get the number," vs. "get the counter document, get the number, increment the counter document."

There are two reasons for incrementing the counter document before getting the users number:

  1. If some validation or something "blows up" before the counter document is incremented, another user could get the same number while the first user is trying to "fix" their validation problem. The first user already has the number, but has not incremented the counter doc.

  2. If by chance two users update the counter document within milliseconds of each other (i.e., a double increment, no replication conflict), there is the potential of both users then getting the same number when the lookup occurs. But this is not a terrible scenario, because you now should have a number that was not utilized and therefore you can "manually" populate one of the documents via an agent with the unused "previous" number.

Hopefully what I wrote is not too confusing as it's kind of hard to describe.

—Brad G.

Do you have comments on this Ask the Expert question and response? Let us know.

Dig Deeper on Lotus Domino Designer

SearchWindowsServer

Search400

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury

SearchDataCenter

SearchContentManagement

Close