cancel
Showing results for 
Search instead for 
Did you mean: 

Auto generated column in datalist

krups
Champ in-the-making
Champ in-the-making
Hello everyone,

I want to generate auto generated ID field in my custom data list could you please help me?

Thanks
9 REPLIES 9

arnoldschrijve1
Champ on-the-rise
Champ on-the-rise
Hi Krups,

You want to auto-generate an ID field upon creation of a new datalist item, right?

Well first of all you could take a look to the DOD5015 project in the Alfresco codebase. You can check it out from the SVN Repository at http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD

The Java package org.alfresco.module.org_alfresco_module_dod5015.identifier contains the implementation of an IdentifierService where you can register your own identifier generators. In the project there is one BasicIdentifierGenerator that creates an id by taking the dbid of the node you provide it.
Identifier generators for different node types are registered with the service by declaring them in the context file (see: /DOD 5015/config/alfresco/module/org_alfresco_module_dod5015/rm-id-context.xml).

You could use this code as the basis for your own project, or if you are by chance using the DOD5015 module, you can declare an identifier bean for your own type (if the BasicIdentierGenerator is sufficient for you).

Now that you are able to generate the ID, you have to automatically assign it to the correct property of your custom datalist type. There are at least 2 ways to do this, both of which involve Java programming. The first one is to implement a node policy for the onCreateNode behavior, call the identifierService there and set your property before it is persisted. The other way is to implement a form filter and handle the beforePersist event where you set your identifier.

The DOD5015 has demonstrations for both of these methods (the project is excellent for learning about Alfresco development). For an example of the first method you can take a look at RecordsManagementAdminServiveImpl.initialiseCustomModel() where the onCreateNode is bound to a method in the class.
In class RecordsManagementTypeFormFilter.afterPersist you'll find an example where an id is generated after a type was persisted. It has a bit of inline code to generate the id.

Hope this gets you started.

arnoldschrijve1
Champ on-the-rise
Champ on-the-rise
BTW If you want to avoid some of the Java coding, you could probably also achieve your objective by adapting the webscripts that handle data-item creation and you could even handle this in client-side code if you were so inclined. But both of these ways are less robust, IMO.

krups
Champ in-the-making
Champ in-the-making
Hi Arnold

I am trying to create OnCreateNode Policy behavior file but don't know where to put this file.
could you please guide me?

Thanks

arnoldschrijve1
Champ on-the-rise
Champ on-the-rise
Krups, you have to create a development project that can hold your Java files. The prefered way is to use the Alfresco SDK and create an AMP extension. See this wiki page for instructions: http://wiki.alfresco.com/wiki/Alfresco_SDK_4.0. While the SDK is using Ant for builds, you could also write your extension using Maven. See: https://code.google.com/p/maven-alfresco-archetypes/

krups
Champ in-the-making
Champ in-the-making
Hi Arnold,

I am really confused.
I have installed eclipse and imported alfresco sdk directory.
I have no idea how to use SDK? I am really new to it.
could you please guide me?

thanks

arnoldschrijve1
Champ on-the-rise
Champ on-the-rise
I cannot help you with this, as I am not using the SDK myself. Maybe you should raise your questions in a separate thread in the appropriate forum.

krups
Champ in-the-making
Champ in-the-making
Hi Arnold,

Thanks for quick reply.
I really appreciate your help.
Is there any way that I can achieve my task ( Auto generated column in datalist) without eclipse or SDK?

arnoldschrijve1
Champ on-the-rise
Champ on-the-rise
You could do it by overriding the webscript that handles a datalist item POST in the repository. The code is located in /Remote API/config/alfresco/templates/webscripts/org/alfresco/slingshot/datalists/data.post.json.js
The actual parsing of the form data takes place in evaluator.lib.js in the run() method.

krups
Champ in-the-making
Champ in-the-making
Hi Arnold,

Sorry for taking time to reply you back but I am still struggling where to start.
I played with data.post.json.js and evaluator.lib.js files but had no luck.
Actually I found one extension module for datalist i.e. http://blog.alfrescian.com/?p=95.
I want exactly same ID sequence functionality what datalist extension module has.
I realized that I can't use this extension because It is not compatible with Alfresco 4.0.d and also not compatible with custom datalist as well.
Could you please help me?

Thanks