cancel
Showing results for 
Search instead for 
Did you mean: 

Document naming / numbering and custom content model

david_labbe
Champ in-the-making
Champ in-the-making
Dear Alfresco community,

being a newb to Alfresco, I have a number of questions regarding custom content and in particular document "naming" / "numbering".

Say the document numbering format used by a company follows a systematic approach, i.e.: XXXX-TYP-XXXX where the first 4 X's represent for example a project code, TYP describes the type of document (Purchase order, Contract, Report, blablabla…) and the last 4 X's is a sequence number tied up with the project code and the document type.

The overall question is: what would be the steps to take to implement such document numbering into Alfresco.

To customise the "Add content" dialog to include the three input (project code, document type, sequence number) is not really a problem. This is described in a number of sources (forum, wiki, books).

The problem lies in the tricky background bit, i.e.:
- determining what is the next available sequence number
- forcing the document to take the name XXXX-TYP-XXXX.ext so that upon downloading, someone gets XXXX-TYP-XXXX.pdf and not "The report I did last week on some project I can't remember the number of".pdf

The next tricky issue is about the actual project code (by the way, I am sure somebody out there will say none of this is tricky, it just is for me as my background is more php that java). I have seen that when creating a custom content model, it is possible to add a property constrained by a list of values defined in the model file, However, although this is very useful for many things, it is unfortunately not very dynamic. It seems rather odd to have to update the model file everytime a new project is created. How possible is it to have an interface within Alfresco to create the projects and thus associate the basic information to the projects and pull out the required project number info to populate the combobox in the custom content model?

This would be extremely useful to know as it also applies to recording the client information, the contractors, etc…

Btw, I am not after re-creating an ERP, just storing a base set of info about projects and clients… to enable easier document management?

I really appreciate any help on the matter.

Kind regards

David

PS: thumbs up to the Alfresco team for a rather amazing product and to the community for their massive contribution on the forum and elsewhere without whom I would still be headbutting my screen on a number of questions
8 REPLIES 8

zladuric
Champ on-the-rise
Champ on-the-rise
The problem lies in the tricky background bit, i.e.:
- determining what is the next available sequence number

What I have for such a purpose is a custom space with a custom properties. I don't have the project names, only ID-s. It works like this: whatever function is in charge of setting the new name gets the last used ID for the new document and names the document as requested, and increments the ID counter.
And I can manually edit this ID any time from  /alfresco.

You could probably use the similar thing for the project codes (only use a list of codes, not a simple counter).

- forcing the document to take the name XXXX-TYP-XXXX.ext so that upon downloading, someone gets XXXX-TYP-XXXX.pdf and not "The report I did last week on some project I can't remember the number of".pdf
Depends on how you decide on what document takes which project code. If it is user-related, you could tie that to the user (or groups, maybe), so if "joe" generates the new doc, the doc will be TEST-TYP-0001.pdf.
Maybe you create these documents in project-specific spaces, you can then use the container names or props to decide what the document name should be. Ie.
if (doc.parent == "Sales") doc.name = "SALE" + getSalesNextID() + '.pdf'
or something like that.
There are various approaches.

The next tricky issue is about the actual project code (by the way, I am sure somebody out there will say none of this is tricky, it just is for me as my background is more php that java). I have seen that when creating a custom content model, it is possible to add a property constrained by a list of values defined in the model file, However, although this is very useful for many things, it is unfortunately not very dynamic. It seems rather odd to have to update the model file everytime a new project is created. How possible is it to have an interface within Alfresco to create the projects and thus associate the basic information to the projects and pull out the required project number info to populate the combobox in the custom content model?
Like I said, it seems to me that you have to set some custom abstract set of properties that you can edit without restarting or anything. Then when you're trying to populate the combobox, get the values from this custom properties.


Hope it helps a bit.

david_labbe
Champ in-the-making
Champ in-the-making
Thanks zladuric for your reply.

I did consider setting the custom "details" as a business rule on a given space. But that is still impractical as the spaces are not organised solely by customer or by project. Similarly, I cannot have a rule setting the name according to the space it is in. One of the space contains the projects. Each project space contains a number of sub-spaces for the project control documents, project templates, client documents, etc… this means that a number of document types are present in a space.

I cannot allow for the user to go and fetch manually the document id from somwhere ( a list, an excel file or other) or update some external source for the sequence number… this is a recipie for disaster as it is extremely easy to make a mistake. We deal with a very large number of documents on our projects and up till now, we had document registries that would automatically produce the numbers required for a new document according to the project and the type. This prevented a few issues on the sequence. Our document numbering is in fact a little bit more elaborate than XXXX-XXX-XXXX. I simply use that example to draw attention to the relationship between the various part of the document number.

It is paramount the system generate the number and not the user.

The question was focused on how can we record the project name ( and code and other info) and the client name (and code, and contact, …) somewhere in Alfresco and re-use that information in a custom content model.

You mention:
Like I said, it seems to me that you have to set some custom abstract set of properties that you can edit without restarting or anything. Then when you're trying to populate the combobox, get the values from this custom properties.

what do you mean by custom abstract set of properties that can be edited without restarting? Could you elaborate and detail how this works.

Thanks

David

zladuric
Champ on-the-rise
Champ on-the-rise
Well,

For example (simplification of what I have):

1. Have a space (not accessible from /share nor to all users in /alfresco, or with read-only access) called "MyCo Settings"
2. Apply your custom aspect on it.
3. The aspect holds the fields/props like:
myco:nextID
mycoSmiley Tonguerojecttypes
or whatever else you need.
4. Fill this fields with your desired values
5. Have your business logic (workflow javascript, webscripts, whatever else you use) access these fields and use them as you need.

For example

function nameDocument(doc)
{
   var docID = companyhome.childByNamePath("Settings").properties["myco:nextID"];
   companyhome.childByNamePath("Settings").properties["myco:nextID"] += 1;
   var projectcode = functionThatDeterminesTheProjectType();
   var department = functionThatGetsDepartmentConstraintsBasedOnProjectCode(projectcode);
  …
  …

doc.name = projectcode + department + docID + datetimestamp + … + '.pdf';
}

You get the idea.

david_labbe
Champ in-the-making
Champ in-the-making
thanks Zlatko,

Nice! I think I get the idea. I am going to have to do a little bit of research to find out to implement all that as I am very new to the whole Alfresco environment and also to the java one but I will give it a try. If you have more tips or details about how to implement your suggestion, I will more than happy to read them. In the meantime, I will give it a try and post my results.

Thanks

David

david_labbe
Champ in-the-making
Champ in-the-making
ok, I probably will look like I am dumb but I am a bit at a loss.
I have created an aspect and the space as per your suggestions. How do you aply the aspect to the space? Is it simply by adding a rule?  Where do I "fill the fields"?

What about the second part of my post related to client? How can I store somewhere a list of clients names that can be updated and that populate a list in a custom content type?

Thanks again for your help.

David

zladuric
Champ on-the-rise
Champ on-the-rise
You don't look dumb at all, I am still asking such questions around Smiley Happy

Anyway, when I want to apply some new aspect or add a new property or whatever, I go to alfresco Data Dictionary, to Scripts space. There I create or upload a javascript file that does what I need, for example:

var myCustomSpace = companyhome.childByNamePath("Custom Space/Settings");
myCustomSpace.addAspect(whateverAspectYouAddedToDataModel);

Then just execute that script. I'm sure there are also easier and better ways to do this.

Ah, you should also update/create your web-client-config-custom.xml file (which defines what fields are visible, and if they are read-only or editable too).

That should be it. Then you can view the new props of that space by navigating to that space and clicking "View details".

You can "Modify properties" there and set the new fields to what you need.

david_labbe
Champ in-the-making
Champ in-the-making
Hi Zlatco,

after a rather hectic few days workwise, I finally got some time to try out your suggestion. I had a few hiccups along the way but managed in the end thanks to your suggestions. I am still a long way from having a proper and robust document numbering but at least with what you gave me, I can do quite a few things. So thank you very much.

To summarise, for those who might want similar functionalities:

Purpose of the exercise: demonstrate how a sequence number can be added to a document name, and incremented automatically

1 - Create an aspect to store the "nextId" number:

in Company Home > Settings > Models, create a new model file called customModel.xml with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<!– Definition of new Model –>
<model name="myCo:model" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!– Optional meta-data about the model –>
   <description>My Company Model</description>
   <author></author>
   <version>1.0</version>

   <!– Imports are required to allow references to definitions in other models –>
   <imports>
      <!– Import Alfresco Dictionary Definitions –>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
      <!– Import Alfresco Content Domain Model Definitions –>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
      <import uri="http://www.alfresco.org/model/system/1.0" prefix="sys" />
   </imports>

   <!– Introduction of new namespaces defined by this model –>
   <namespaces>
      <namespace uri="myCo.model" prefix="myCo" />
   </namespaces>

   <aspects>
   
      <!–  Definition of Settings Aspect: settings –>
      <aspect name="myCo:settings">
         <title>Settings</title>
         <properties>
            <property name="myCo:nextId">
               <title>Next Id</title>
               <type>d:text</type>
               <protected>false</protected>
               <mandatory>true</mandatory>
               <multiple>false</multiple>               
            </property>
         </properties>
      </aspect>
   
   </aspects>

</model>

2 - Ensure the newly created aspect in your model is available in the Action wizards by updating (or creating) the web-client-config-custom.xml file located in Company Home > Settings > Models > Web Client Extension:

<alfresco-config>
   
   <!– List the custom aspects and content types shown in the business rules Action wizard –>
   <config evaluator="string-compare" condition="Action Wizards">
      <aspects>
         <aspect name="myCo:settings"/>
      </aspects>
   
   <config evaluator="aspect-name" condition="my:settings">
      <property-sheet>
         <separator name="sepCli1" display-label="Settings" component-generator="HeaderSeparatorGenerator"/>
         <show-property name="myCo:nextId"/>
      </property-sheet>
   </config>

</alfresco-config>

3 - Reload your web-client-config-custom.xml changes using the web-client:
http://localhost:8080/alfresco/faces/jsp/admin/webclientconfig-console.jsp

Use the "reload" command.

4 - Create the "Settings" space in the Company Home root

5 - Go to the "Settings" space and click on More Actions > View Details

6 - In the actions box, click on Run Action and select "add and aspect"… and select "settings" in the next window… Once this is done, you can set the initial value of your nextId…

7 - Write little script that you will store in Company Home > Scripts:

var settings = companyhome.childByNamePath("Settings");

var docId = parseInt( settings.properties["myCo:nextId"] );
settings.properties["myCo:nextId"] = docId + 1;
settings.save();

document.properties.name = document.name + "-" + docId;
document.save();


8 - In a newly created space where your documents will go, add a rule to the space based on the execution of a script… select the script and voila…


Note: this is extremely basic, but I am sure it can be useful for more elaborate scripts!

Hope this will be useful to someone.

Thanks again to Zlatco for his help.

Regards

David

susmera
Champ in-the-making
Champ in-the-making
I am using SDK and maven to run the project.I am a beginner so could you please explain the steps 3 to 7.