How to use relative date in nuxeo StudioHow to use relative date in nuxeo Studio

Here’s a question about relative date usage in Nuxeo Studio: How do I pass a date, relative to the current date, into a Query Filter?

This is interesting as sometimes you might want to retrieve all documents with an expiration date before today plus 30 days. Or maybe you want to retrieve every document created thirty days ago. You obviously can’t hardcode the date so you have to use something like a @{CurrentDate} object.

Content Automation

If you’re in the content automation context, it’s really straight forward. Most of the operation parameters support the MVEl scripting language. So you have access to any objects like @{CurrentDate}.

Here’s a query that returns the documents that will expire in the next 10 days:

 SELECT * FROM Document WHERE dc:expired BETWEEN @{CurrentDate} AND @{CurrentDate.days(10)}

While this retrieves all the documents that have been expired at least 10 days:

 SELECT * FROM Document WHERE dc:expired <= @{CurrentDate.days(-10)}

Content Views

Unfortunately, this won’t work in a content view. The problem is that the @{CurrentDate} object (notice the first letter, upper-case C) is only available in the MVEL context. This means that it will work fine in an operation, but it won’t be available as a parameter of a ContentView. Something quite misleading is that there is a #{currentDate} (first letter, lower-case c) object available in the context of a ContentView. It’s outjected by SEAM and is an instance of java.sql.Date, which means you can’t use the days method. There is currently no way to have a relative date with this particular Date object.

So if you want to have a specific parameter, you’ll have to create a seam bean with the appropriate method or factory and use it as a query parameter for your content view. Of course this is not ideal, but we will work on this and try to find a simpler solution.