cancel
Showing results for 
Search instead for 
Did you mean: 

Using node-dbid to create a unique document number

neilecker
Confirmed Champ
Confirmed Champ

My organization migrated from a system that had an automatic document numbering system which many users found useful.  The nodeRef is certainly unique but isn't something that you could easily read to someone over a phone call.

Just wondering if there are any reasons why using the sys:node-dbid property would be a bad idea to generate a unique document number to insert in a custom property.  It's unique to the respository so that part is good.  Would I ever run into a problem when upgrading to a newer version of Alfresco?

Below is the simple test script and rule I created.

GRY - AutoNumber.js

var dbid = document.properties['sys:node-dbid'];
document.properties['gry:fileNumber'] = 'DOC_' + dbid;
document.save();

Simple rule on folder to run the above script:

2 REPLIES 2

afaust
Legendary Innovator
Legendary Innovator

The node DB ID will end up as a non-consecutive document ID since Alfresco creates quite a number of "invisible" nodes in the background that each get their own DB ID, so there will be ID gaps between business documents. If you copy or check out a document you will likely end up with two documents having the same ID - not a problem with the checkout, but a problem if the copy ends up having a life of its own.

What if you need a separate type of ID with a distinct numbering scheme down the line?

Also, exposing the DB ID is exposing technical information that may be used for finding attack vectors, e.g. if you have enabled the inbound email server functionality, this allows you to send emails at nodes identified by their DB ID to e.g. post comments to documents.

For proper document IDs it is always recommended to use business-driven IDs, generated independant from technical identifiers. Ususally, that is a requirement best suited for implemention via Java behaviours / services in combination with e.g. the AttributeService as the store for a system wide ID counter / ID inventory.

Thanks for the feedback!

The non-consecutive numbers aren't a problem for us and document copies do get a new ID with the simple rule created in the original post but I do see how this is not really ideal.  It didn't really sit right with me and I'll look into using the AttributeService as that seems to be a better option.  This must be a very common request, are there any good examples out there of people doing this or something similar?