xpages partial - full search - xpages

I saw a great tutorial from IBM explaining creating a search modulo into a view panel.
The code from the viewpanel ( search property ) I adjusted:
"(Field txt_autor = \"" + sessionScope.searchAutor + "\")";
}
Is there any chance I can modify the code so that it offers the search results for the partial string matches also, for example: if Autor = Smith and in the string searchAutor = Smit currently I get 0 documents / 0 results. Something like CONTAINS will be useful, if it's possible.
Thanks for your time.

Add a star "*" in front and at the end of every search string like "*Smit*".
Your code would look like this then
tmpArray[cTerms++]= "(Field txt_titlu = \"*" + sessionScope.searchTitle + "*\")";

Related

Adding values to multi-value field and displaying them

I have 3 multi-value fields and I have already inserted values in them. All of the fields are Text type, edible. What I'm trying to do is that I want to add functionality in xpages, so that I can add new values to those fields.
Here's what I got so far:
The code that triggers on the save button:
var statuss = document1.getItemValue("statuss");
var stat_vec:java.util.Vector = document1.getItemValue("statuss_update");
stat_vec.add(statuss);
document1.replaceItemValue("statuss_update", stat_vec);
var vards = session.getEffectiveUserName();
var vards_vec:java.util.Vector = document1.getItemValue("name_update");
vards_vec.add(vards);
document1.replaceItemValue("name_update", vards_vec);
var laiks = session.createDateTime("Today");
var laiks_vec:java.util.Vector = document1.getItemValue("time_update");
laiks_vec.add(laiks);
document1.replaceItemValue("time_update", laiks_vec);
document1.save();
The code that I have atteched to the computedField, where the values are displayed from the 3 multi value fields + it refreshes when I insert new values:
var x = document1.getItemValue("statuss_update");
var y = document1.getItemValue("name_update");
var z = document1.getItemValue("time_update");
var html = "<head><link rel=\"stylesheet\" type = \"text/css\" href=\"test.css\"></head><table id=\"tabula\">";
for (i = 0 ; i < x.size()-1; i++){
html= html + "<tr><td>" + x[i] + "</td><td>" + y[i] + "</td><td>" +z[i] + "</td></tr>";
}
html = html + "</table>";
I can insert the values and they get displayed in the HTML table but the problem is with saving the edits. Whenever I try to save the document (I have a save button that has save document event attached to it) I get the error:
Could not save the document 1B06 NotesException: Unknown or
unsupported object type in Vector
As far as I understand I'm trying to savesomething in a field, where the values type is not supported. Can anyone give me a hint what am I doing wrong or where to look for the problem? Been stuck with this for a pretty long time.
Is it this part?
var statuss = document1.getItemValue("statuss");
var stat_vec:java.util.Vector = document1.getItemValue("statuss_update");
stat_vec.add(statuss);
It looks like you're getting the statuss item's values (potentially a Vector??) and adding it to the Vector for statuss_update. If it's definitely just one value, getItemValueString() would work better.
I'm nnot sure if this is right, but you mention all fields are Text type, but it looks like you're passing a DateTime to the third one.
It might be worth analysing the contents of the Vectors before it's doing the save, just to make sure they contain what you expect.

Tracking document content changes

I'm trying to track the history of field values that are displayed in computed field as HTML. So far I got this:
var x = document1.getItemValue("category");
var html = "<table>";
for (i = 0 ; i < x.size(); i++){
html= html + "<tr><td>" + x + "</td></tr>";
html = html + "<tr><td>" + session.getEffectiveUserName() + "</td></tr>";
}
html = html + "</table>";
The code works ok, I get the value that I need and it gets displayed and if I edit the current document, the value changes via partial update that I have attached to the save button, but that's not the problem. The problem that I have is with saving it. I thought of creating an array and adding the value that changed but it will reset everything because of the script. Any suggestions how I can save that value or add it to the field? I was using Append ToTextList in forms, is there any way how to achieve that functionality in Xpages?
You can add a new value in a field in the querySave of the DominoDocument in XPages:
var x = document1.getItemValue("category");
x.add(myNewValue);
document1.replaceItemValue("category", x);
Chris Toohey just posted a blog article that seems to be what you're looking for.
http://www.dominoguru.com/page.xsp?id=thoughts_on_future_proofing_notesdata_for_application_development.html

Populate Drop Down List Box (DDLB) with two values in PowerBuilder

I've created a Drop Down List Box (DDLB) in my window (I'm using PowerBuilder 10.5). Once I would call my function, the DDLB would fill with all the different cities from my table. This is the code I've used:
FOR li_i=1 TO ii_br_red
ls_city = dw_city.GetItemString(li_i, 'city')
IF ddlb_city.FindItem(ls_city, 1) = -1 THEN
ddlb_city.AddItem(ls_city) END IF; NEXT
Next part of the code is in the ddlb "selectionchanged" event...
dw_city.SetFilter("city = '" + this.text + "'")
dw_city.Filter()
This works great, and after calling my function (via click on a command button) I'd get a list of all different cities in my table, ex.
Paris
London
New York
Washington
No town would be listed twice.
What I need to do now is add a country next to every city in my DDLB. So that after clicking my command button I would get this in my DDLB:
Paris (France)
London (GB)
New York (USA)
Washington (USA)
Any advice? Thanks in advance...
SECOND QUESTION, similar to this subject: I have an SQL code:
SELECT distinct name FROM table1;
This gives me 8 different names. What I want to do is fill another DDLB, ddlb_1 with these names, but this must occur on the open event of my program. This is what I've written in the open event of my program:
string ls_name
SELECT distinct name INTO :ls_name FROM tabel1;
ddlb_1.AddItem(ls_name)
But this only gives me the first name. I'm guessing I need some kind of count, but I just can't pull it off.
If you do not want to change the design of the program, and as you states that the country is in the same DW, you could hack the code a little to add the country to the ddlb (I suppose that the country is available on the same row of the dw):
String ls_country
FOR li_i=1 TO ii_br_red
ls_city = dw_city.GetItemString(li_i, 'city')
IF ddlb_city.FindItem(ls_city, 1) = -1 THEN
ls_country = dw_city.GetItemString(li_i, 'country')
ddlb_city.AddItem(ls_city + ' (' + ls_country + ')')
END IF
NEXT
A quick and dirty hack to get back the value in the event to filter the DW would be
int p
string ls_city
ls_city = this.text
p = pos(ls_city, '(')
if p > 0 then ls_city = left(ls_city, p - 2) //skip the "space + (country)" part
dw_city.SetFilter("city = '" + ls_city + "'")
dw_city.Filter()
But this kind of code is difficult to maintain and should be replaced by something else, as the processing of the city value is strongly coupled to its representation in the list.
A better solution would be a dropdowndatawindow, or (worse) an array of the cities names where the index of a city + country in the ddlb would correspond to the index of the bare city name suitable for filtering the DW
I think you should modify the "source" datawindow' select, and you should get the final result which you want, and you would only need to copy the datas from the datawindow to the ddlb. You should use distinct in the select something like this:
select distinct city + ' (' + country_code + ')' from cities_and_countries_table
of course you should replace the "city", "country_code" to the actual column name in your table as well the table-name. With this you will get every city only once and they will be already concatenated with the country code.
Br. Gábor
Does it really have to be DDLB? I would give the user a Single Line Edit for the city name and filter the DW as the user types.
To answer my own second question, this is how I've done it finally...
String ls_name
DECLARE xy CURSOR FOR
SELECT distinct name FROM table1;
OPEN xy;
FETCH xy INTO :ls_name;
do until sqlca.sqlcode <> 0
ddlb_1.AddItem(ls_name);
FETCH xyINTO :ls_name;
loop
CLOSE xy;
I'm new to PowerBuilder, But I just used that kind of scenario, however I used a DDW (Drop Down Data Window) Instead of a List Box On this case, you can display more than one column as soon as the DW gets the focus and you'd be able to dynamically populate the data. Give it a try. It worked for me, DW's are a pain in the neck when you're just starting (as in my case) but you can do a lot with it

search view with the exact value

I have a view in which I search for products. I'm for example looking for product 1234.
The problem is their also exist products called 1234A and 1234 C etc. When I look with the code mentioned below I get all the items from product 1234 but also from 1234A and 1234 C etc.
It has to be limited to items from product 1234 only
Search code (under Data / Search in view results):
var tmpArray = new Array("");
var cTerms = 0;
if (sessionScope.SelectedProduct != null & sessionScope.SelectedProduct != "") {
tmpArray[cTerms++] = "(FIELD spareProduct = \"" + sessionScope.SelectedProduct +
"\")";
}
if (sessionScope.Development != null & sessionScope.Development != "") {
tmpArray[cTerms++] = "(FIELD spareStatus = \"*" + sessionScope.Development +
"*\")";
}
qstring = tmpArray.join(" AND ").trim();
return qstring
I used the suggestion from Frantisek :
I made a view with a combined column . (combined with the different "keys" I search for)
Then instead of using data / search , I used data/keys with exact keymatch. In this key I combined the searched items.
Since I had a field in wich I had sometimes at the end a character "°" , and it seems that this character doesn't work with a lookup , I took it out of my view and searched item with #Word(FIELDNAME; "°" ; 1).
As Frantisek suggested I could have used #ReplaceSubstring( field; "°"; "" ) also.

How do I filter a dojo grid on an xpage?

How do we filter the dojo grid (extlib component) that gets its data from the REST service component? I have the grid loaded with data from the view correctly from the REST service component. I also have on the xpage a dropdown where users can select a value that's a dbcolumn of one of the columns in the same view. I've tried setting the REST service keys value to viewScope.filterCat01 (which is the variable for the combo box), and I've also tried setting the filter in a button (BY is the field/column name) but nothing seems to filter it. Any ideas? In the button when I check grid properties, it does work, so I know the grid object is valid - but the filter just doesn't seem to be doing anything. I've also tried doing a grid._refresh() as well as setting the Keys in the REST service component with no luck. Is there a special way to trigger the filter?
var filterValue = XSP.getElementById("#{id:comboBox2}").value;
var grid = dijit.byId("#{id:djxDataGrid1}");
grid.filter({ By: filterValue});
This is definitely one of those things that you need to piece together a thousand cryptic clues to work it out (Domino - never!). Anyway, I had to work this one out last year. Here's an example 'search' button:
var searchText = dojo.byId('#{id:searchText}').value.replace(/"/g, '|"');
if (searchText) {
var ftSearchText = '[Title] CONTAINS "' + searchText + '" OR [Description] CONTAINS "' + searchText + '" OR [URL] CONTAINS "' + searchText + '"';
dijit.byId('#{id:grid}').filter('?search=(' + ftSearchText + ')', false);
} else {
dojo.byId('#{id:reset}').click();
}
As you can see, it's doing an ft search when a filter is applied. The key is to put "?search=" on to the beginning of the filter string.
and here's the 'reset' button example:
dojo.byId('#{id:searchText}').value="";
var grid = dijit.byId('#{id:grid}');
grid.filter("",true);
grid.store.close();
grid._refresh();
This was developed with 8.5.2. There might be some cleaner ways to do things in 8.5.3 with dojo 1.6.1.
Enjoy!

Resources