How to get date information

Hi all,

first of all congratulations for this forum where answers are usually quick and precise. It is really a helpful forum.

Back to work…

I have followed the tuto in Nuxeo Studio documentation to create some document number id automatically based on prefix and GetNextId function and I was wondering if there is any function to get some date format extraction in order to customize my document id. Let's say I want my document id to contain two digit corresponding to week number (1-52) and two digit corresponding to the 2 last digits of the year (ex 12 for this year 2012).

Is there any function available to return this like in some other language (php for instance).

Thank you for your help

Snarf

0 votes

1 answers

919 views

ANSWER



No, I don't think, so. There is no specific function that does that.

My piece of advice would be to create your own operation. If you have just a little notion of development you can do it really really easily.

Nuxeo provides Nuxeo IDE integrated with Nuxeo Studio. Here is steps to follow:

  • Install Nuxeo IDE and create an empty project
  • Create a new empty Operation. You just have to click on the yellow “NX” button > Automation > Operation
  • Select your project, give a package (for instance “com.yourcompany.yourproject.automation”), the name of your operation, id of your operation (Fill.ID for instance), Category CAT_DOCUMENT, let uncheck “Require Seam Context”, let Document selected for Input and Output. And let “Iterable Operation” checked.
  • In the run method you can implement your logic to create the ID and fill the document.

You must something like that:

@OperationMethod(collector=DocumentModelCollector.class)
public DocumentModel run(DocumentModel input) {
   ... do the code that create the id with the date on 2 digits and put the value into the id parameter ...
   input.setPropertyValue("prefix:field", id);
   // where prefix is the prefix of your schema and field the name of the field where you want to store the id generated
}    

In this operation we don't save the document so think to add in your chain a SAVE operation after (without that the value will be not saved).

0 votes