Using CurrentDate in NXQL

Hi!

In Nuxeo 6.0 HF 38 I'm trying to use CurrentDate in NXQL in avanced search or by quering http://nuxeoserver/nuxeo/api/v1/query

When I try this, it works: http://nuxeoserver/nuxeo/api/v1/query?query=SELECT * FROM Document WHERE dc:created > TIMESTAMP '2017-04-04 00:00:00'

But this doesn't work : http://nuxeoserver/nuxeo/api/v1/query?query=SELECT * FROM Document WHERE dc:created > TIMESTAMP '@{CurrentDate.days(-1).format(“yyyy-MM-dd HH:mm:ss”)}'

I get this error : {“entity-type”:“exception”,“code”:“org.nuxeo.ecm.webengine.WebException”,“status”:400,“message”:“Failed to execute query: java.lang.IllegalArgumentException: Invalid format: "@{CurrentDate.days(-1).format("y…" in query: SELECT * FROM Document WHERE dc:created > TIMESTAMP '@{CurrentDate.days(-1).format("yyyy-MM-dd HH:mm:ss")}'“}

Thanks for help.

0 votes

2 answers

1330 views

ANSWER



Hi, did you try: “SELECT * FROM Document WHERE dc:created <= DATE '@{CurrentDate.format("yyyy-MM-dd HH:mm:ss")}'”

Or you can have a look to https://answers.nuxeo.com/general/q/23699bc926634b439b552c3848e12ad1/How-do-I-pass-a-date-relative-to-the-current-date-into-a-Query-Filter

1 votes



Hi Saimir,

With this : http://nuxeoserver/nuxeo/api/v1/query?query=SELECT * FROM Document WHERE dc:created <= DATE '@{CurrentDate.days(-1).format(“yyyy-MM-dd HH:mm:ss”)}'

I got the same error : {“entity-type”:“exception”,“code”:“org.nuxeo.ecm.webengine.WebException”,“status”:400,“message”:“Failed to execute query: java.lang.IllegalArgumentException: Invalid format: "@{CurrentDate.days(-1).format(“y…" in query: SELECT * FROM Document WHERE dc:created > DATE '@{CurrentDate.days(-1).format(“yyyy-MM-dd HH:mm:ss”)}'“}

When I use this query (the same in my first question) in an automation chain it works : SELECT * FROM Document WHERE dc:created > TIMESTAMP '@{CurrentDate.days(-1).format(“yyyy-MM-dd HH:mm:ss”)}'

but it dosen't work in the API Url nor in NSQL Advanced search.

Thank you.

0 votes



Hi, You can't access mvel ( "@{CurrentDate.days(-1)") function here because at this point it is out of context. I suggest You to build some client code witch will call the rest service : http://nuxeoserver/nuxeo/api/v1/query?query=&apos;your query' , You can format query with parametres as you want. Some useful docs https://doc.nuxeo.com/nxdoc/rest-api/
Thanks
06/12/2017

OK that's why. Thank you Saimir for your help.
06/12/2017

you're welcome
06/12/2017