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

nativesonn
Champ in-the-making
Champ in-the-making
"I created a JavaScript to generate a unique Document Id based on the property you mentioned and it works Smile
Added this to an inbound rule, so now every new document created has a identifier DD00xxxx."

theorbix
Confirmed Champ
Confirmed Champ
Thanks Kevin.

I created a JavaScript to generate a unique Document Id  based on the property you mentioned and it works Smiley Happy
Added this to an inbound rule, so now every new document created has a identifier DD00xxxx.


Regards,

Alex

Hi, I have the some problem that you have mentioned earlier ?
?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).?
? and I need to make visible that number to the end-users. Can you help me? Or someone else?

Hi nativesonn and mrosado…  have you found a way to implement this feature? Can you share the JavaScript, or the "trick" you used?

I need to implement exactly the same behaviour: I want to create a Space to store commercial offers. When a new offer is uploaded in the Space, a new, progressive unique number should be automatically generated and stored in a custom document property.

theorbix
Confirmed Champ
Confirmed Champ
Add the following to your web-client-config-custom.xml file:

   <config evaluator="aspect-name" condition="countable">
      <property-sheet>
         <show-property name="counter" read-only="true" />
      </property-sheet>
   </config>

The purpose of this counter is to display the current value of the counter incremented by the "Increment counter" rule, right?

But when this counter is actually incremented? Kevin wrote:

The Increment Counter action is an action that can be used to log counts to a document. It increments a counter value against a node with every execution.

That's OK… but what does "execution" actually mean? Every time the rule is executed?

So, assuming that the rule is defined to run on every new inbound document, when I save the first document into the area, the counter should be "1", when I save a second document it should become "2"…. correct?

kevinr
Star Contributor
Star Contributor
Yes every time the rule is one. The existing counter action takes the value from a property attached to the document itself. So the value is not incremented system wide - it is relative to the document, so not really what you want i think.

Kevin

theorbix
Confirmed Champ
Confirmed Champ
Yes every time the rule is one. The existing counter action takes the value from a property attached to the document itself. So the value is not incremented system wide - it is relative to the document, so not really what you want i think.

Kevin

You're 100% right… unfortunately Smiley Sad

So, what could be the steps to define a "custom counter property", that is incremented automatically, at the Space level, every time a new document is stored in the Space?

With "Space level", I mean that the value of the counter should be incremented indipendently in every single Space in which I'll add the custom aspect (or custom rule… whatever is required to achieve my purpose).

theorbix
Confirmed Champ
Confirmed Champ
OK, I think that I made some little progress… I have created a new custom aspect ("DocumentID") and associated to the documents in a Space.

Then, I have created the following JavaScript and then I have used the "Run Action" command to execute it:

// change the name of this document
document.properties["customSmiley Very HappyocumentID"] = 1234;
// save the property modifications
document.save();

It works properly, and it stores the value 1234 in the document ID field of the document details.

Now I just need to create a progressive counter that will be incremented at every new document stored in the space.

I will clearly need to store, somewhere in the repository, the last value used for the counter.

And since the value of the counter should be unique for every Space in which I'll use the custom aspect, I was thinking to store the last value of the counter in a "LastDocumentID" custom property associated to each Space.

Now, what is the exact JavaScript syntax required to retrieve the value of a given property from the space that "owns" a document?

Ideally the code should look more or less like (but I'm not sure if the getparent() method actually exists…):

ParentSpace = document.getparent();
LastDocID = ParentSpace.properties["custom:LastDocumentID"];
NewDocID = LastDocID + 1;
ParentSpace.properties["custom:LastDocumentID"] = NewDocID;
ParentSpace.save();
document.properties["customSmiley Very HappyocumentID"] = NewDocID;
document.save();

alarocca
Champ in-the-making
Champ in-the-making
I would suggest you a different way. Create an aspect to apply the DocumentID to any content by means of a rule. You have also to implement an aspect behaviour to initialize its value as you like (eg. a counter from a database query). Finally add the new property to the property-sheet as read-only and expose for advanced search.

See wiki and sdk for details about the Aspect Behaviour.

theorbix
Confirmed Champ
Confirmed Champ
I would suggest you a different way. Create an aspect to apply the DocumentID to any content by means of a rule. You have also to implement an aspect behaviour to initialize its value as you like (eg. a counter from a database query). Finally add the new property to the property-sheet as read-only and expose for advanced search.

See wiki and sdk for details about the Aspect Behaviour.

Thanks for the hint. I'll double check the documentation (although I did a quick search on the Wiki but "aspect behaviour" only shows a long list of quite generic content…).

Must an Aspect Behaviour be defined with Java coding, or is it possible to also use JavaScript?

Just to know, was there something fundamentally wrong in my approach? In other words: I guess that defining a custom aspect with a custom aspect behaviour is more "elegant", but would my approach work - at least for a POC?

alarocca
Champ in-the-making
Champ in-the-making
You are right. Aspect behaviour is not documented on the wiki. Just a reference to the CustomAspect sample within Alfresco SDK. Anyway, it is a good reference.

Aspect Behaviour needs really few code specially if you would just initialize a field (implements NodeServicePolicies.OnAddAspectPolicy) and a bean definition to provide the nodeService and the policyComponent. Get the CustomAspect sample and put away what you don't need.

What I suggested you is just a different approach. I cannot say that it is better because I have not knowledge of the Alfresco JavaScript capacity.

theorbix
Confirmed Champ
Confirmed Champ
Thanks Alarocca for the reply.
Good points.

I believe I will continue to make some experiments with the JavaScript approach, at least from a POC (Proof of Concept) standpoint.

In the meanwhile I'll try to understand a bit more about Aspect Behaviours….