Web UI Framework

How to Set a Default Date on a Field at Document Creation

Updated: October 16, 2020

A frequent requirement with documents is to set a default date on a field when showing the creation form. This how-to will teach you how to do it easily using Nuxeo Studio's event handlers and automation chains.

Creating the Event Handler

In Nuxeo Studio, go to Automation > Event handlers and add a new event handler. Name it and click Next.

In the Event Handler Definition section, make sure to select the event "Empty document created". This event will be fired right before the document form creation is shown to the user.

In the Event Handler Enablement section, you may add filters to define conditions for your event handler to be used. You may relate it to a certain document type for instance, especially if you need to fill a document type specific field.

Creating the Associated Automation Chain

Now that you have setup when the event handler will take place, it is important to tell what it will do. To do so, in the Event Handler Execution section click on the button Create. Note that you may also use an existing automation chain if you created it previously.

Name your chain and click on OK.

In the automation chain, use the following operations and parameters:

OperationParameterValue
Fetch > Context document(s)  
Document > Update propertyValue@{CurrentDate.calendar}
 Xpathschema:field

And that's it! Note that the previous parameter will set today's date, but you may use Nuxeo Studio's expression builder to change it. Many possibilities exist in that regard.