0

I have tried several times to enter a date range into the Search in view. The search string i put into Search in view is as follow.

compositeData.Operasjon = "ST-MOD"

" FIELD OprPlanGruppe_1 = " + compositeData.Operasjon + " AND FIELD OprDato_1 = " +

    dates.substring(0, dates.length() - 1);

The result is that only the last key value pair (FIELD OprDato_1 = 11.02.2014) is used to filter

The hole code is below:

    var idag:java.util.Date = new java.util.Date();
var cal:java.util.Calendar =java.util.Calendar.getInstance();
var dateFormat:java.text.SimpleDateFormat = new java.text.SimpleDateFormat("dd.MM.yyyy");

cal.set(java.util.Calendar.HOUR_OF_DAY, 0); // ! clear would not reset the hour of day !
cal.clear(java.util.Calendar.MINUTE);
cal.clear(java.util.Calendar.SECOND);
cal.clear(java.util.Calendar.MILLISECOND);

var dates = "";
var i;

for(i = 0; i < 7; i++){
    cal.set(java.util.Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek() + i);
    dates += dateFormat.format(cal.getTime()) + ",";
}

dates = dates.replace("undefined", "");
return " field OprPlanGruppe_1 = " + compositeData.Operasjon + " AND FIELD OprDato_1 = " + dates.substring(0, dates.length() - 1);

Is there any possibilities to add more than one value after Field in the filter query?

Ex: FIELD OprDato1 = 10.02.2014,11.02.2014

Lothar Mueller
  • 2,528
  • 1
  • 16
  • 29
Kjell Dirdal
  • 11
  • 2
  • 4
  • http://stackoverflow.com/questions/2479555/search-for-a-date-between-given-ranges-lotus – Frantisek Kossuth Feb 14 '14 at 15:12
  • @Frantisek: I'm not sure whether the question you have linked really is related to this one here: here we are asked about a FT Search within XSP, there the question relates to a NotesDatabase.Search in LotusScript, using an Formula syntax...; I removed the "lotus-notes" tag to reduce confusion – Lothar Mueller Feb 14 '14 at 16:49
  • One of the problems might be the syntax you're using: a search using `FIELD OprDato1 = 10.02.2014, 11.02.2014` will find documents with `10.02.2014` in `OprDato1` OR `11.02.2014` in any field. You need to enclose that query in parentheses: `FIELD OprDato1 = (10.02.2014, 11.02.2014)` if you want to search only in that field. – Mark Leusink Feb 14 '14 at 19:31
  • I have tried to enclose them with parantheses. Same result – Kjell Dirdal Feb 14 '14 at 20:16

1 Answers1

0

You want to show all documents in view which have in field "OprDato_1" a date that is within the current week. You use the "Search in view results" property of xp:viewPanel. It uses full text search and has to have the syntax of full text search. You can compare dates with ">=" and "<=". So, an easy way to look for dates in a certain date range is

FIELD OprDato_1 >= 10.02.2014 AND FIELD OprDato_1 <= 16.02.2014

or shorter as

[OprDato_1] >= 10.02.2014 AND [OprDato_1] <= 16.02.2014

Your code for calculating the search string would look like this:

var cal:java.util.Calendar =java.util.Calendar.getInstance();
var dateFormat:java.text.SimpleDateFormat = new java.text.SimpleDateFormat("dd.MM.yyyy");
cal.set(java.util.Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
var firstDate = dateFormat.format(cal.getTime());
cal.set(java.util.Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek() + 6);
var lastDate = dateFormat.format(cal.getTime());
return "FIELD OprPlanGruppe_1 = " + compositeData.Operasjon + 
       " AND FIELD OprDato_1 >= " + firstDate + 
       " AND FIELD OprDato_1 <= " + lastDate

This code calculates the date range for current week. You are free to set cal to any other date and date range would then be the week of this date.

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • What I disovered is that the field OprDate_1 is of type String not date. Can't compare string with date without convert the string to date. Can't do this in ftsearch directly. Works on converting text to date. – Kjell Dirdal Feb 16 '14 at 11:17
  • In case you have to stay with text in OprDate_1 you can create search string like this: `... AND ([OprDato_1] = "10.02.2014" OR [OprDato_1] = "11.02.2014" OR ... OR [OprDato_1] = "16.02.2014")`. But, it would be better you convert your search field to date as it would be independent from local settings then. To save date and time in strings is always "dangerous". – Knut Herrmann Feb 16 '14 at 12:21
  • @user2599699: could you get it to run? Does full text search work now? – Knut Herrmann Feb 18 '14 at 16:17
  • Yes. I had to import the date as DateTime. Through session.createDateTime. now I can search for date compare. This for some reason only possible in xPage. Not in the Lotus View. I guess that the database is corrupt somehow. – Kjell Dirdal Feb 19 '14 at 18:25
  • I am glad you got full text search to work for your XPage. It's weird that full text search in Notes client doesn't show same results... – Knut Herrmann Feb 19 '14 at 19:36