cancel
Showing results for 
Search instead for 
Did you mean: 

How to fill custom prop with DocId like unique identifier?

alexr
Champ in-the-making
Champ in-the-making
We are in the process of migrating from Stellent/Intradoc to Alfresco.
One of the features of Intradoc is having a simple document Id as a read-only field that will be used by end-users to refer to in business communications (email, other documents etc.).
The DocId has the following format: AA006001, AA006002 etc. Since it's an simple number to communicate and not a cryptic number like for instance a Documentum Document Id starting with 09…….. etc.
I know a unique record identifier is something that is touched upon by record management, but I am only looking for this specific feature.

Then I came across the Action "Increment Counter"  as a create rule feature.

What counter is this and can it be read/manipulated from within a JavaScript.

The node-id of documents is quite cryptic, so I can't see how I can convert this to a simple but Unique doc identifier.  Haven't found a JavaScript method to retrieve node-id's.


I have to be sure that there is a automatic mechanism that generates a unique number each time content is added (either through a rule or otherwise).

What would be the simplest approach? I want to keep things as default and simple as possible. At the moment there is no need for implementing a Records Management solution.

Kind regards,

Alex
37 REPLIES 37

theorbix
Confirmed Champ
Confirmed Champ
Ok, I did it… and no Java coding was required, just some JavaScript.

Here are the steps:
1) I've created a custom aspect called "DocID"
2) I've assigned the aspect to a Space
3) I've set up a rule in the space. On every new document stored in the space the rule does two things:
- assigns the "DocID" aspect to the document
- runs a certain JavaScript script

And here is the content of the script:

____
// Retrieve the last DocID value from the counter at the Space level
LastDocID = parseInt(space.properties["customSmiley Very HappyocID"]);
// Generate new DocID value
NewDocID = LastDocID + 1;

// Store the new value in the space
space.properties["customSmiley Very HappyocID"] = NewDocID;
space.save();

// Store the DocID in the document's metadata
document.properties["custom:numprotocollo"] = NewDocID;
document.save();
____

Thanks to all who provided suggestions…

johanpi
Champ in-the-making
Champ in-the-making
The following worked for me    (wfl:ReferenceNo is the result)

var currentSpace = document.parent.parent.parent;
var date = new Date();
var record = document.child;
var contentfile = document.parent;

document.properties["wflSmiley TonguerojectName"] = currentSpace.name;
document.properties["wflSmiley TonguerojectID"] = "ECM002";
document.properties["wflSmiley TonguerojectManager"] = "Johan Pieterse";
document.properties["wflSmiley Very HappyocumentDate"] = date;

// Get the current record count
var countAction = actions.create("counter");
countAction.execute(contentfile);
document.properties["wfl:ReferenceNo"] = contentfile.properties["cm:counter"];

document.save();

ivo_costa
Champ in-the-making
Champ in-the-making
Hi

johanpi, I don't know if I got your code right, but wouldn't that duplicate reference numbers if you delete a few files before adding new ones?

TheOrbix, I liked your solution, but I was wondering if there isn't any other way to set a permanent variable on an Alfresco System
On the other way your solution can provide viewable information without the need to create too much code

thanks
Ivo Costa

johanpi
Champ in-the-making
Champ in-the-making
I should have cleaned my code before pasting….

What is does is in this case is use the description from the space (RFQ), take the current year (2008) and append the counter (1) example: RFQ/2008/1

When adding content it will append a new counter - number for each item added. If you delete it, the counter will carry on as if it still exists.

var contentfile = document.parent;
var curr_year = date.getFullYear();

// Get the current record count
var countAction = actions.create("counter");
countAction.execute(contentfile);
document.properties["wfl:ReferenceNo"] = space.properties["cm:description"] + "/" + curr_year + "-" + contentfile.properties["cm:counter"];

document.save();

ivo_costa
Champ in-the-making
Champ in-the-making
My bad johanpi

I thought that you where counting the number of files in the space, but I can see now that the countAction is really updating the counter

johanpi
Champ in-the-making
Champ in-the-making
No problem

For the others a bit more.

Add the code in a script (AddCounter.js in my case).
I then created a rule
In step 2:
Step Two - Select Actions
1.    Select Action
     Execute a script
2.    Click to set values and add to list
     
Selected Rule Actions
Summary   
Executes script 'AddCounter.js'     RemoveChange

It will then execute the script to calculate the next number and add it to some field (metadata) every time new content is added.

zomurn
Champ in-the-making
Champ in-the-making
Hum…I simply created a custom model that inherits of cm:content…this latter inherits of sys:base and this latter contains a referenceable aspect witch contains a sys:node-dbid value. This latter is unique and is applied to every node in the system.
Then through inheritance, you can easily acces to the property sys:node-dbid from your own model.

ivo_costa
Champ in-the-making
Champ in-the-making
zomurn, that only gives you a random number, and that doesn't work for official documents.
Official Document's serial number are usually sequencial…

like 1452/98 (document 1452 of the year 98)

or like TS9932/98 ("top secret" 9932 of 1998)

evilattorney
Champ in-the-making
Champ in-the-making
I'm trying to implement unique document ID's.  However I am unable to find clear instructions on how to create a custom model to follow your instructions.  Could someone point me to some instructions?

Also, I noticed that each document had a field named "Email ID".  Is this a unique value that could be used/referenced or am I misunderstanding what it is used for?

johanpi
Champ in-the-making
Champ in-the-making
Yes the "Email ID" is unique.