Xpages view after search - search

How can I get a column documents from a view after search? I know that with #DbColumn(#DbName(),"viewName",#) I can get the # column documents from the view, but it is not updating after search... The values are the same as before filtered...
Any ideas?
Thanks,
Florin

You could do a search in your view via SSJS and then loop through the entry collection afterwards to fetch the column values, e.g.
var view = database.getView("myView");
var col = view.search("searchformula", null, 0);
var ent = col.getFirstEntry();
while(ent!=null){
var colvalue = ent.getColumnValues()[index];
ent = col.getNextEntry(ent);
}

Related

Xpages: Keep view sort order when filtering on view

My Xpage has a dataView that points to a view which is sorted by employee name. One of the other fields in the employee view is their Location. I have a combobox in the header of the view that allows a user to subset to one location. When subsetted the correct employees appear, but the sort order is lost.
I have looked at a few answers in Stack overflow such as this and this. but cannot get them to work. I think the difference is that
I am not trying to filter on a value that is sorted.
Here is my code for the FT Search:
var tmpArray = new Array("");
var cTerms = 0;
//Geo Location Search
if(viewScope.key != null & viewScope.key != "" & viewScope.key != "All Locations" & viewScope.key != "--Select a Location--") {
tmpArray[cTerms++] = "(FIELD HR_GeoLocation = " + viewScope.key + ")";}
qstring = tmpArray.join(" AND ").trim();
viewScope.queryString = qstring; // this just displays the query
return qstring // this is what sets the search property
The view's first field is the users last name, first name, descending.
FTSearch doesn't return found documents in view's order:
The collection of documents that match the full-text query are sorted
by relevance, with highest relevance first.
Use an additional view which is categorized by Location and use Location as key in
Filter by category name (categoryFilter) or
Filter by column value
(keys/keysExactMatch)
The columns after Location-column are the same as in your current view.

mutivalue date field search not working

I have a multivalue field called freeDaysPool which has multiple dates as strings. With the following code, the search does not return anything. If I leave that field out, the search works just fine with the two other fields. I read that I should use CONTAINS with multivalue fields but then I got query not understandable.
I've tried the back-end field as a date field and as a text field and tested all kinds of query combinations and date formats but no luck. Any help is really appreciated.
This is the search button code:
var query = new Array("");
var cTerms = 0;
// Field 1
var search01 = getComponent("searchcustomReservationField01").getValue();
if (#Contains(#Text(search01),"any city")){"";}
else {query[cTerms++] = '[customReservationField01]="' + search01 +'"'};
// Field 2
var search02 = getComponent("searchcustomReservationField02").getValue();
if (#Contains(#Text(search02),"any city")){"";}
else {query[cTerms++] = '[customReservationField02]="' + search02 + '"'};
// Date 1
var formatter = new java.text.SimpleDateFormat("d.M.yyyy");
query[cTerms++] = 'FIELD freeDaysPool = ' + formatter.format(getComponent("searchcustomDateField01").getValue());
// if query is still empty, we fill it with asterisk
if(query == "" || query == null){
query[cTerms++] = "*";
}
// make all as string
qstring = query.join(" AND ").trim();
sessionScope.searchString = qstring;
It will return query as:
[customReservationField01]="Oslo" AND [customReservationField02]="Oslo" AND FIELD freeDaysPool = 6.2.2015
AFAIK date values in formulas (and a query is a formula) have to be noted like
[06.02.2015]
to compare them. Just try to use your formular in the Notes Client to do a fulltext search. If you get results and no errors you found the correct format. That's at least the way I test queries as I'm not able to remind the syntax for years :-D
Thank you for all the help! Seems that Domino keeps the field type as date field even if you change it back to text field (noticed that from the notes FTsearch). I created completely new text field and added the days as strings in dd.MM.yyyy format. I also search them as strings and it works fine.
The changed code bit now looks like this:
// Date 1
var formatter = new java.text.SimpleDateFormat("dd.MM.yyyy");
query[cTerms++] = '[freeDays] CONTAINS "' + formatter.format(getComponent("searchcustomDateField01").getValue())+'"';

Get entries count for a multiple category view (two categories) using a key (Xpages)

I am trying to retrieve the entries count for a multiple category view (two categories) using a key.
var db:NotesDatabase = session.getDatabase(sessionScope.serverPath,sessionScope.dbName);
var luview = db.getView(sessionScope.viewName);
var vec:NotesViewEntryCollection = null;
if (key != null) {
vec = luview.getAllEntriesByKey(key);
}
count = vec.getCount().toFixed()
The count being returned is incorrect. I have over 500 documents in the view. It seems to be returning just the document count (20) of the first sub-category.
I've found mention of this as a bug in the forums. I'm running this on a 9.0 server. Any pointers would be much appreciated.
What I would like is the total count - categories (25) + documents (500), that I can use in the repeat control limit.
Thanks,
Dan
I was able to resolve this by using the NotesViewNavigator.
var nav:NotesViewNavigator = v.createViewNavFromCategory(key);
var entry:NotesViewEntry = nav.getFirst();
while (entry != null) {
count = count + 1;
var tmpentry:NotesViewEntry = nav.getNext(entry);
entry.recycle();
entry = tmpentry;
}
Dan - If you can get the entry count into the view column with an #AllChildren... or #AllDecendents or something like that then using the view navigator you should be able to read that value in and not have to actually loop through all the documents.
Another way is to create a different view, could be hidden, and not categorize that second column. Then you're original solution should work I'd think.

Is there any way i can get handle on value from views Column header?

Is there any way i can get handle on value from views Column header??
I have one view and i have to display only selected column values inside a table with respect to the selected column header.
var colNames = new Array(); var Title=sessionScope.dbTitle;
var vwName = sessionScope.vwTitle;
print ("view name"+ vwName);
if ((vwName != null) & (vwName != "Select")) { //var vwName="vwDbConfig";
print (vwName);
var dbpath=#DbLookup("","vwDbConfig",Title,3);
var serName=#DbLookup("","vwDbConfig",Title,2);
var ArchDb:NotesDatabase = session.getDatabase(serName,dbpath);
//var ArchDb:NotesDatabase= database;
var Archvw:NotesView = ArchDb.getView(vwName);
var names:java.util.Vector = Archvw.getColumnNames();
Answer is: two repeats. Outermost repeat will iterate through view entries of binded view data source, variable "row". Inner repeat will iterate through collection of numbers - each represents index of selected column, variable "column". Repeat will render inside <td> tag computed text with binding row.getColumnValues().get(column). Adopt it to proper data type if necessary. Don't forget to add proper tags for header and rows.

How do I search Google Spreadsheets?

I am doing a few exhaustive searches and need to determine if a new domain (URL) is already in a Spreadsheet. However, none of the Spreadsheet objects have search functions, namely findText() found in most Document objects. I feel like I am missing something significant.
What am I missing?
findText function: https://developers.google.com/apps-script/class_table#findText
SearchResult object: https://developers.google.com/apps-script/class_searchresult
Spreadsheet object: https://developers.google.com/apps-script/class_sheet
My best guess is to try and convert specific Spreadsheet ranges in Document tables, then perform the search. Mendokusai
Unfortunately there is no searching functionality in the Spreadsheet services. You can get the data for the range you are searching on, and then iterate over it looking for a match. Here's a simple function that does that:
/**
* Finds a value within a given range.
* #param value The value to find.
* #param range The range to search in.
* #return A range pointing to the first cell containing the value,
* or null if not found.
*/
function find(value, range) {
var data = range.getValues();
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < data[i].length; j++) {
if (data[i][j] == value) {
return range.getCell(i + 1, j + 1);
}
}
}
return null;
}
I wrote a search tool with a graphical user interface that performs a global search in 3 columns of a single sheet. It could be easily modified to suit your needs. I guess it would be a good idea to add an anchor in the UI to let you open the url you just found.
Here is the code, hoping it will help you to design your own version.
EDIT : I added the anchor widget in the code below (getting its ref in column E)
// G. Variables
var sh = SpreadsheetApp.getActiveSheet();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var lastrow = ss.getLastRow();
//
function onOpen() {
var menuEntries = [ {name: "Search GUI", functionName: "searchUI"},
];
ss.addMenu("Search Utilities",menuEntries);// custom menu
}
// Build a simple UI to enter search item and show results + activate result's row
function searchUI() {
var app = UiApp.createApplication().setHeight(130).setWidth(400);
app.setTitle("Search by name / lastname / adress");
var panel = app.createVerticalPanel();
var txtBox = app.createTextBox().setFocus(true);
var label=app.createLabel(" Item to search for :")
panel.add(label);
txtBox.setId("item").setName("item");
var label0=app.createLabel("Row").setWidth("40");
var label1=app.createLabel("Name").setWidth("120");
var label2=app.createLabel("Lastname").setWidth("120");
var label3=app.createLabel("Street").setWidth("120");
var hpanel = app.createHorizontalPanel();
hpanel.add(label0).add(label1).add(label2).add(label3)
//
var txt0=app.createTextBox().setId("lab0").setName("0").setWidth("40");
var txt1=app.createTextBox().setId("lab1").setName("txt1").setWidth("120");
var txt2=app.createTextBox().setId("lab2").setName("txt2").setWidth("120");
var txt3=app.createTextBox().setId("lab3").setName("txt3").setWidth("120");
var hpanel2 = app.createHorizontalPanel();
hpanel2.add(txt0).add(txt1).add(txt2).add(txt3)
var hidden = app.createHidden().setName("hidden").setId("hidden");
var subbtn = app.createButton("next ?").setId("next").setWidth("250");
var link = app.createAnchor('', '').setId('link');
panel.add(txtBox);
panel.add(subbtn);
panel.add(hidden);
panel.add(hpanel);
panel.add(hpanel2);
panel.add(link);
var keyHandler = app.createServerHandler("click");
txtBox.addKeyUpHandler(keyHandler)
keyHandler.addCallbackElement(panel);
//
var submitHandler = app.createServerHandler("next");
subbtn.addClickHandler(submitHandler);
submitHandler.addCallbackElement(panel);
//
app.add(panel);
ss.show(app);
}
//
function click(e){
var row=ss.getActiveRange().getRowIndex();
var app = UiApp.getActiveApplication();
var txtBox = app.getElementById("item");
var subbtn = app.getElementById("next").setText("next ?")
var txt0=app.getElementById("lab0").setText('--');
var txt1=app.getElementById("lab1").setText('no match').setStyleAttribute("background", "white");// default value to start with
var txt2=app.getElementById("lab2").setText('');
var txt3=app.getElementById("lab3").setText('');
var link=app.getElementById('link').setText('').setHref('')
var item=e.parameter.item.toLowerCase(); // item to search for
var hidden=app.getElementById("hidden")
var data = sh.getRange(2,2,lastrow,4).getValues();// get the 4 columns of data
for(nn=0;nn<data.length;++nn){ ;// iterate trough
if(data[nn].toString().toLowerCase().match(item.toString())==item.toString()&&item!=''){;// if a match is found in one of the 4 fields, break the loop and show results
txt0.setText(nn+2);
txt1.setText(data[nn][0]).setStyleAttribute("background", "cyan");
txt2.setText(data[nn][1]);
txt3.setText(data[nn][2]);
link.setText(data[nn][3]).setHref(data[nn][3]);
sh.getRange(nn+2,2).activate();
subbtn.setText("found '"+item+"' in row "+Number(nn+2)+", next ?");
hidden.setValue(nn.toString())
break
}
}
return app ;// update UI
}
function next(e){
var row=ss.getActiveRange().getRowIndex();
var app = UiApp.getActiveApplication();
var txtBox = app.getElementById("item");
var subbtn = app.getElementById("next").setText("no other match")
var hidden=app.getElementById("hidden");
var start=Number(e.parameter.hidden)+1;//returns the last search index stored in the UI
var item=e.parameter.item.toLowerCase(); // item to search for
var txt0=app.getElementById("lab0");
var txt1=app.getElementById("lab1").setStyleAttribute("background", "yellow");
var txt2=app.getElementById("lab2");
var txt3=app.getElementById("lab3");
var link=app.getElementById('link').setText('').setHref('')
var data = sh.getRange(2,2,lastrow,4).getValues();// get the 4 columns of data
for(nn=start;nn<data.length;++nn){ ;// iterate trough
if(data[nn].toString().toLowerCase().match(item.toString())==item.toString()&&item!=''){;// if a match is found in one of the 4 fields, break the loop and show results
txt0.setText(nn+2);
txt1.setText(data[nn][0]).setStyleAttribute("background", "cyan");
txt2.setText(data[nn][1]);
txt3.setText(data[nn][2]);
link.setText(data[nn][3]).setHref(data[nn][3])
sh.getRange(nn+2,2).activate();
subbtn.setText("found '"+item+"' in row "+Number(nn+2)+", next ?");
hidden.setValue(nn.toString())
break
}
}
return app ;// update UI
}// eof 05-12 Serge insas
I ended up using spreadsheet formulas to solve my problem instead. Specifically, I used the MATCH() function, which can look up a string in an array (in this case a column in another sheet in the same document).
This is significantly simpler than looping through an array, though less efficient and does not allow for full automation. In fact, when the column reached 2,000 entries, Google Drive froze so often, I had to start using Excel instead. Nevertheless, the Match() solution was more appropriate for what I was looking for.
Appreciate all the other responses though.
You can "search" using the SpreadsheetAPI List Feed query parameter. This will return any row that matches using full word matching. Throw some asterisks around your parameter (URL encoded of course) and it becomes wildcard.
I have not tried it, but it appears that the Google Visualization API Query Language will allow you to execute SQL queries against Google sheets.

Resources