Doing a query on a BDM custom that has a date

Hi Community,

I have a BDM model that contains a list of events that are created by date (DATE ONLY). 

I created a custom query to return all events for a period of time. The dateFrom and dateTo are defined as parameters of type java.time.LocalDate

SELECT e 
FROM Evenement e
WHERE e.dateEvenement >=  :dateFrom
AND c.dateEvenement <=  :dateTo
 

In a page, I used 2 standard date picker with a technical date format of  yyyy-MM-dd to get the From and To date and try to query the BDM but it always retunred a 500.

{
    "exception": "class org.bonitasoft.engine.exception.BonitaRuntimeException",
    "message": "USERNAME=walter.bates | java.lang.IllegalArgumentException: unable to parse \\u0027\\u00222022-01-01T00:00:00.000Z\\u0022\\u0027 to type java.time.LocalDate"
}

Here is the request that was generated by the UI:

http://localhost:8081/bonita/API/bdm/businessData/com.company.model.Evenement?q=findByDate&p=0&c=1000&f=dateFrom="2022-01-01T00:00:00.000Z"&f=dateTo="2022-01-31T00:00:00.000Z"

 

Doing some test, I found out that the following query works. The difference being that the date is not quoted, it has to be sent in this format and does not have the time.

http://localhost:8081/bonita/API/bdm/businessData/com.company.model.Evenement?q=findByDate&p=0&c=1000&f=dateFrom=2022-01-01&f=dateTo=2022-01-31

 

I was able to get around this issue by generating the complete query parameter using javascript and storing it in a variable (queryparam) and adding it to an external API

External API: 
../API/bdm/businessData/com.company.model.Evenement?{{queryparam}}

 

Javascript:

var formControl ={};

$data.queryparam = 'q=findByDateEntraineurPlus&p=0&c=1000&f=dateEvenementFrom=' +  $data.dateDu.toISOString().slice(0,10) + '&f=dateEvenementTo=' + $data.dateAu.toISOString().slice(0,10);

return formControl;

I find this to be a very ugly workaround, is there an easier way to pass the date to the BDM without the javascript?

Thanks.

Hi,

 

Inspired by this documentation page: https://documentation.bonitasoft.com/bonita/2021.2/pages-and-forms/datetimes-management-tutorial

I would suggest the following:

In the External API variable use a syntax like dateFrom={{dateVar | uiDate:'YYYY-MM-dd'}}

This way the query parameter of your API call is formatted the way it is expected by the API. 

Let me know if that works for you,

Captain Bonita