Search code examples
xpages-ssjs

ServerSide Javascript ftSearch with DateTime


I would like to use ftSearch in ServerSideJavascript but I cannot go beyond with datetime value of field. What i want to do is I would like to get all Document after a specified Datetime not only date. I need Date and exac time together with.

var cDate:NotesDateTime = doc.getItemValueDateTimeArray("createdAt").elementAt(0);
var dateFormatter = new java.text.SimpleDateFormat("dd.MM.yyyy hh:mm:ss" ); 
var query = "(FIELD Form=\"Calculate\" AND FIELD Location= \"" + lks+ "\"";
query+= " AND FIELD _createdTime>" + cDate; 
query+=")";
var dc:NotesDocumentCollection = database.FTSearch(query, 0);

EveryTime i get this error
ERROR: java.lang.IllegalArgumentException: Cannot format given Object as a Date"

DateTime Field properties like this **

Field Name: createdAt
Data Type: Time/Date
Data Length: 8 bytes
Seq Num: 1
Dup Item ID: 0
Field Flags: SUMMARY 
11.03.2019 15:54:10 ZE3

**

UPDATE V2 I get an error If i use date with time. is it possible to use it like below..
Exception occurred calling method NotesDatabase.FTSearch(string, number) Notes error: Query is not understandable
((FIELD Form="FormName" AND FIELD Location= "Test" AND FIELD cDate>21.03.2019 10:54:20))


Solution

  • Convert your cDate to Java Date and then to String.
    Replace cDate in query with:

    dateFormatter.format(cDate.toJavaDate())