Question

I made an xpage element for ftsearch using a tutorial from IBM

My request: is there possible having 2 date fields ( as input requirements for the search ) to find those documents having the creation date inside the interval consisting of those 2 dates?

Should I create a computed field dtCreated where I will store the creation date and then in the search property of the view I should add something like this:

      var tmpArray = new Array("");
        var cTerms = 0;
        if (sessionScope.searchDate1) && (sessionScope.searchDate2) {
        tmpArray[cTerms++] = "(Field dtCreated > \"" + sessionScope.searhcDate1 + "\")" && "(Field dtCreated < \"" + sessionScope.searhcDate2 + "\")";
        }
    ....
    ....

Or there is another alternative?

My 2 session variables are having Short (5/5/14) Date format. Also, my default value for those 2 dates (session variables) are "" but of course I add some values before clicking the Submit button.

Thanks for your time!

Was it helpful?

Solution

You can use the special field _creationDate as creation date (see answer from Tommy). Based on this the following example query will work in the Notes client:

Field _creationDate > 01-01-2014 AND Field _creationDate < 01-03-2014

In order to get this query to work with your specific code do this:

var tmpArray = new Array("");
var cTerms = 0;
var dateFormatter = new java.text.SimpleDateFormat( "dd-MM-yyyy" ); 
if (sessionScope.searchDate1) && (sessionScope.searchDate2) {
    tmpArray[cTerms++] = "Field _creationDate > " + dateFormatter.format(sessionScope.searchDate1) + " AND Field _creationDate < " + dateFormatter.format(sessionScope.searchDate2);
}

OTHER TIPS

If you want to do an FTSearch, _CreationDate can be used

Documentation (scroll to Searching for Header Information): http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=%2Fcom.ibm.designer.domino.main.doc%2FH_CUSTOMIZING_SEARCH_FORMS_7304.html

E.g. (there might be typos):

tmpArray[cTerms++] = "(Field _creationDate>" + sessionScope.searhcDate1 + ") AND (Field _creationDate<" + sessionScope.searhcDate2 + ")";

Or my preferred syntax:

tmpArray[cTerms++] = "[_creationDate>" + sessionScope.searhcDate1 + "] AND [_creationDate<" + sessionScope.searhcDate2 + "]";

To build on Tommy's answer:

Specifically, try "yyyy/m/d" as the format. If those values in sessionScope are java.util.Date (the type that date fields use), you could try something like this (typing off the top of my head, not in an app, so my apologies for typos):

var tmpArray = [];
var cTerms = 0;
if(sessionScope.searchDate1 && sessionScope.searchDate2) {
    var formatter = new java.text.SimpleDateFormat("yyyy/M/d");
    tmpArray[cTerms++] = "[_CreationDate] >= " + formatter.format(sessionScope.searchDate1) + " and [_CreaationDate] <= " + formatter.format(sessionScope.searchDate2)
}

What you want to end up with is a FT query like:

[_CreationDate] >= 2014/1/1 and [_CreationDate] <= 2014/2/1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top