cancel
Showing results for 
Search instead for 
Did you mean: 

Help in creating documents

franksant13
Champ in-the-making
Champ in-the-making

Hello everyone, I am new to Alfresco and I am working on a project in which I have to create a folder where all the stored files are going to be of the same format (word or pdf) and each file must have the same name only differentiated by a number. This number represents the document number and must also be included in the content of the document. Users will create these documents from a template and the document number must be assigned automatically. If you could give me a hand to know where to start or which way to go, will help me a lot.
Thanks in advance

5 REPLIES 5

calvo
Star Collaborator
Star Collaborator

Hi,

Maybe a first approach could be something like this:

- Define a content rule on an specific folder

- On create document, this rule will execute a script.

This script return number of documents of the folder and change de name of document to: "samename_returnedvalue"

¿The number of document should be in the text of document or like a property?

Regards,

clv

franksant13
Champ in-the-making
Champ in-the-making

Thanks for your response my friend.

I need to have the document number in the text of the document. It is not necesary to have it as a property. 

Do you know any tutorial to help me starting with usign scripts in alfresco?

jpotts
World-Class Innovator
World-Class Innovator

There are three parts to your question.

First, automatically generating a document number. To do that, consider writing a "service" class that is responsible for handing out document numbers. It's up to you whether you store the number in a database or somewhere in the repository. Many people prefer to just write a little JSON document in the Data Dictionary that tracks document numbers.

Next, you want to insert the number into the content of a file. This is tricky because if you are dealing with a variety of binary file formats, you'll potentially need an API for each one. You also need a way to specify where in the file the document number will be placed.

If you could simplify your requirement to a specific file type that would help. For example, if you were to only need to insert the doc number into Word documents, you could use docx4j. I like docx4j because it is easy to do simple things like create a document template that has a placeholder, then send key-values to the API to replace the placeholders with the values. You can place this logic in a general "doc generation" service class.

Last, how you actually trigger the generation and insertion. As Jose mentioned, a rule is probably the best approach here. The rule should probably invoke a Java-based rule action class that leverages the autonumber service and the "doc generation" service mentioned above.

franksant13
Champ in-the-making
Champ in-the-making

Thanks for your response... can you please be a litlle more specific in how to do the "Service" in the first part. Im new in Alfresco.

For the other parts of your response i think i am only going to use word files to avoid the problems you describe.  

jpotts
World-Class Innovator
World-Class Innovator

Sure, you'll create a project using the Alfresco SDK. That will give you a Maven-based source code structure that will allow you to compile an AMP (Alfresco Module Package) that you will deploy to your WAR.

A service is just a class that is responsible for some specific operation. There are many many examples of this pattern, but here is a simple one that is easy to get your head around:

GitHub - Conexiam/alfresco-acl-templates: Facilitates the creation of multiple named Access Control ... 

That's a source code project for a repository-tier AMP that does one thing: Retrieves and applies "ACL templates" on a given node. The actual service class implementation is alfresco-acl-templates/AclTemplateServiceImpl.java at master · Conexiam/alfresco-acl-templates · Git... 

So you'd create an AutoNumberService.java class where your autonumbering logic would reside. It might have a method called getNextNumber() or something like that.

Then you'd also create a DocumentGenerationService.java class where your doc generation logic would reside. It might have a document called resolvePlaceholders(Map<String, Object> placeholderMap, NodeRef nodeRef) or something like that.

Of course each of these might be worthy of being in completely separate projects/separate AMP files, but that's up to you.

Finally, you'll create something like DocumentNumberActionExecuter.java that will be your custom rule action. It will leverage both of these services to actually perform the action on a document when it is added to a folder.

If this is new to you I'd recommend working through my tutorials. If you have problems, create a new post with the specifics and someone will help.