views:

164

answers:

4

For the documents stored in the database, I would like to create a human readable key to uniquely identify the document. e.g. PO20090110-001. How do I go about doing that?

+1  A: 

It's not simply.

Create field for uniquely key and this key saving onSave (or other event), but you must protect this number to be unique.

You can create agent, which checking number on domino server and if agent find conflict then notify application administrator or other responsibility person to resolve this.

Or each replica generate own number and after replicate on domino, agent assign number in right format.

MicTech
+1  A: 

One solution used in our help desk is to take the initials of the current user and add it to the a number in the last document in a view. Add one to the number and store that it the new document along with the ititals and the new number as the key.

Martlark
+1  A: 

When saving a document you can put together the first part of the number by using the date or any technique you like (ej. "PO" & format(date, "YYYYMMDD") & confDoc.getitemvalue("doccounter")).

As for the counter I like to store it in a configuration document and update it when each doc is saved. If there are lots of documents created during the day you can run into rep conflicts on you configuration document, if this is the case you can have an agent on the server do the actual assigning of the number, the drawback to this is that you don't get the number right away when saving.

Hope this helps.

Carlos
Just a note; You can avoid most replication conflicts on the configuration document by locking it before grabbing the next number. If you assign numbers only when the client can fetch the counter from the administration server, you should be pretty safe.
Anders Lindahl
Very good point. I would be careful though with the doc locking feature, I've had document locked permanently and other weird stuff happen.
Carlos
+1  A: 

You can create a "nearly" unique key in Domino simply by using the @Unique function, with no arguments. This will generate a string key, based on the current user's first and last name and the current clock time. You will end up with a string something like: "ESCR-12345678".

I say "nearly" unique, because it is not really like an identity column in SQL - Domino does not guarantee it will only give out a particular string once. If you use @unique in a server-side agent which generates many id's at once - for example, and agent that loops and uses @unique within the loop, you can get into a situation where @unique will return a duplicate - because you create 2 docs within the same second and because your "username" is always the server's canonical name. But, outside of that scenario, @unique is generally safe to use.

If you then need to open or reference docs by this ID, just create a view sorted by that ID and you can a url in the form ../myView/id?readDocument.

Ed Schembor