‎2020 Aug 05 1:40 PM - edited ‎2024 Feb 03 7:03 PM
I created a new ItemType (SalesData), and trying to execute a simple query via program, it's not returning any results. Where as while debugging, I copied the query and the associated query parameters and executed on hac, that query returned results. Why this query is not working via program? Earlier, I hardcoded some datetime value in the query and it worked. But when I made it like below, it's not working.
private static final String SALES_QUERY = "SELECT {"+ SalesDataModel.PK +"} FROM {"
+ SalesDataModel._TYPECODE + " AS F } "
+ "WHERE {F:" +SalesDataModel.PUBLISHED + "} = false "
+ "AND {F:" + SalesDataModel.TRANSACTIONDATE + "} >= ?fromDateTime "
+ "AND {F:" + SalesDataModel.TRANSACTIONDATE + "} < ?toDateTime ";
private static final String FROM_DATE_TIME = "fromDateTime";
private static final String TO_DATE_TIME = "toDateTime";
private void generateSalesFile(LocalDateTime yesterdayMidnight, LocalDateTime todayMidnight) {
FlexibleSearchQuery query = new FlexibleSearchQuery(SALES_QUERY);
query.addQueryParameter(FROM_DATE_TIME, java.sql.Timestamp.valueOf(yesterdayMidnight));
query.addQueryParameter(TO_DATE_TIME, java.sql.Timestamp.valueOf(todayMidnight));
final SearchResult<SalesDataModel> result = flexibleSearchService.search(query);
...
}
Request clarification before answering.
I updated the 'query.addQueryParameter' code to use Date and it worked.
query.addQueryParameter(FROM_DATE_TIME, Date.from(yesterdayMidnight.atZone(ZoneId.systemDefault()).toInstant()));
query.addQueryParameter(TO_DATE_TIME, Date.from(todayMidnight.atZone(ZoneId.systemDefault()).toInstant()));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.