0
votes

I have a viewpanel in an XPage that has its search value "Search in Search Results" set to a sessionScope variable called queryString. it is set with the following formula...

var tmpArray = new Array("");
var cTerms = 0;
if (sessionScope.SearchTourArea != null && sessionScope.SearchTourArea != "") {
    tmpArray[cTerms++] = "(Field TourArea = \"" + sessionScope.SearchTourArea + "\")";
}
if (sessionScope.SearchTourRegion != null && sessionScope.SearchTourRegion != "") {
    tmpArray[cTerms++] = "(Field TourRegion = \"" + sessionScope.SearchTourRegion + "\")";
}
qstring = tmpArray.join(" AND ").trim();
sessionScope.queryString = qstring;
return "Query = " + sessionScope.queryString

Within the view, in the "Search in search results" I use the formula;

return sessionScope.queryString;

This all works and returns the correct results, however my problem is that it seems to remember this sessionScope variable, so if I include the following code, it will open the page saying there are "34 tours found that suit your choice" when i haven't yet set the search criteria.

if (getComponent("viewPanel1").getRowCount() == 0){
 return "Sorry, we dont yet have any Tours for this combination. Please change some of your choices"
 } else {
return getComponent("viewPanel1").getRowCount() + " tours found that suit your choice"
 }

I'm at a loss. I think all i need to do is reset the sessionScope variable to "", but dont seem to be able to do it.

thanks in advance,

1
You don't state where sessionScope.queryString being set. Please add that information and/or confirm the code is being run again when you expect it to.Paul Stephen Withers
I agree with what Paul said. A sessionScope variable is saved across the session so once set it will be reused unless changed. You can change to use a viewScope variable instead.Per Henrik Lausten
Sure, once the user selects the field values (activity, sub activity etc). They then click on a button that performs a partial refresh on a computed field that works out/displays the formula and the view needs to be refreshed. The code works perfectly whenever it is run, the only part I am struggling with is that it the view seems to retain the number of results, even if it isn't showing them. I have tried the viewScope, but it wasnt doing it as well as i wanted. Is there a way to clear the sessionScope on opening an XPage - and the resulting view results? thanks again.smacca01
You can reset sessionScope variable in beforePageLoad event.Knut Herrmann
Hi, thanks, I tried that but it didn't seem to effect the view count at all. I used sessionScope.queryString ="". Is that correct? Thanks again.smacca01

1 Answers

0
votes

A sessionScope variable is saved across the session so once set it will be reused unless changed. You can change to use a viewScope variable instead.