This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Apr 29, 2013, 7:09 PM
453 Posts
topic has been resolvedResolved

Search In view Results

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.3
  • Role: Developer
  • Tags: search in view results
  • Replies: 11
 I am having trouble with the "Search in view results" formula on a dataview. I want it to return only documents where the current user is a member of a specific field in the document. It is also a column in the Notes View. So I created the following formula in the Search in view results:
 
view1.setSelectionFormula ("SELECT (@IsMember(@UserName(),ACCurrentApprovers)")

 

When I try to view this I get a run time error  in both Nptes and the web.
 
The database is full Text Indexed and the field ACCurrentApprovers is a multi value field. Been looking for example to use but could find little documentation.
 
Thanks
 
Apr 30, 2013, 3:08 AM
110 Posts
Re: Search In view Results
 If I understand your question correctly, what you are doing is changing the view selection formula for the real view you use to create view1. You can check that view and you'll see that the view selection formula change to that which is not really a good practice if other user is trying to access that view because the selection formula always changes.

Also that has nothing to do with the case where the database is full-text indexed. 

However, the search in view results that you are trying to use is actually using full-text index so you are good to go. Which means your code view1.setSelectionFormula ("SELECT (@IsMember(@UserName(),ACCurrentApprovers)") is not correctly applied here.

What you need is go to here  , search for 'query syntax', read it up and build a string of query syntax to be computed into 'search in view results'.

My guess is your syntax is going to be something like this: 

 FIELD ACCurrentApprovers CONTAINS this user

By the way, go and reset the selection formula first. 
May 1, 2013, 10:53 PM
453 Posts
Re: Search In view Results
After posting my original query I realized that I really did not want to reset the Selection formula but do a full text search. I have created the following code in the search for the the dataView in question


var user = context.getUser().getFullName();
var qString  = "(FIELD ACCurrentApprovers CONTAINS \"" + @UserName() + "\")"
return qString

I have used both the var user and the @UserName() but with either case I geta 500 Internal Server Error.

From what I have read and looked  seen this should work. It compiles without error.

I'm at a bit of a loss on this.  
May 2, 2013, 12:13 PM
4 Posts
Debugging approach
Baxter's latest makes sense. Failing that, I would probably try debugging like: Make sure the db is full-text indexed. (I know, duh, right? But I've overlooked that before more than once.) I'd also make sure the query works in Notes, with the specified view. First I would probably do a print statement to check in the server console the name values you're trying, so I could use them in the query in Notes.
May 2, 2013, 6:04 AM
110 Posts
Re: Search In view Results
 Try putting this instead in the search in view result (just 1 line of code):

"FIELD ACCurrentApprovers CONTAINS "+session.getCommonUserName()  

If error occurs again, try open your database in designer > Application Configuration > Xsp Properties > Under 'Error handling', check the 'Display XPage runtime error page' > Try previewing again. Check what are exactly the errors.
May 2, 2013, 5:10 PM
453 Posts
Re: Search In view Results
Boy do I feel dumb, I had been working on a DB that was full text indexed, switched DB and the new one was not.

The code:

"FIELD ACCurrentApprovers CONTAINS " + session.getCommonUserName()

does not throw an error and seems to do the selection correctly except the names in ACCurrentApprovers are in the format CN=SomeName/O=SomeOrg. I substituted getUserName() and I get the error that the query is not understandable. Tried @UserName() with the same result. From the documentation that I have seen both should just return a String value in the form CN=SomeName/O=SomeOrg. Am I missing something?

I changed the code to:

var us:String = session.getUserName()
"FIELD ACCurrentApprovers CONTAINS " + session.getCommonUserName()

this does not throw an error but gives the wrong results, then I changed it to

var us:String = session.getUserName()
"FIELD ACCurrentApprovers CONTAINS " + us
 

and I get the error query is not understandable.  

I put the code session.getUserName() in a computed field in the pagerTop and it displays the full users name correctly so it does not appear to be an issue with session.getUserName in a Data View. This process is really getting "not understandable"

Thanks for the help. 
May 6, 2013, 12:00 PM
4 Posts
Print statement to admin console?
Are you able to insert a print statement to check the search queries that these code statements evaluate to? I tend to rely on that pretty heavily so I can see what's really going on. That, and trying the resulting search query in Notes. The idea of putting the username in quotes also sounds promising. "FIELD ACCurrentApprovers CONTAINS \"" + us + "\""
May 4, 2013, 4:09 AM
14 Posts
Re: Search In view Results
Because the username surely contains spaces you have to wrap the us variable inside double quotes in the query string..
May 9, 2013, 1:24 AM
453 Posts
Re: Search In view Results
Get it to work with this:

 

"FIELD ACCurrentApprovers CONTAINS " + "\"" + context.getUser().getDistinguishedName() + ""\"; 
May 13, 2013, 3:48 PM
453 Posts
Re: Search In view Results
This is really strange

I have set the var user to the distinguished name  :

var user:String = context.getUser().getDistinguishedName(); 

then make the query
 

tmpArray[cTerms++] = "(FIELD ACCurrentApprovers CONTAINS \"" + user + "\")";
and it fails to find any documents, however if I set the var user to the Common Name

  var user:String = @Name("[CN]",context.getUser().getDistinguishedName());

it finds the correct users, which is OK until there are two people in the organization with the same common name but in different OU's  

would the "/" in the distinguished name CN=Some Name/O=Some Org causing problems. Clearly ACCurrentApprovers is fully distinguished as is the getUser().getDistinguishedName()


I've got it working but not deliverable.   
 
May 14, 2013, 3:22 PM
4 Posts
I see the same behavior
If I use Notes search with FIELD editorlist CONTAINS "CN=Michael Stewart/OU=Cambridge/O=IBM" I see the same behavior: No results. If I do this, I get the results I expect: FIELD editorlist CONTAINS Michael Stewart AND FIELD editorlist CONTAINS Cambridge AND FIELD editorlist CONTAINS IBM It does seem like that distinguished name string is a problem in itself. No idea why, but does this alternate approach help at all?
May 14, 2013, 10:11 PM
453 Posts
Re: Search In view Results
Yes it is a bit of a kludge but will work around the issue. I would think that (field Contains @UserName) would be a pretty standard search. I'd tend to call it a bug rather than an undocumented enhancement! :-) But a generalized case would require that I parse out the CN. OU, and O into separate variable then formulate the query. Because not every organization uses the OU, you would need to check if it is blank otherwise the field CONTAINS "" would fail. Just looks like a ton of extra effort for no reasonable gain. And that does not cover the several hours I've spent so far just to find out it was not my code, but what I would call a bug because if you enter the query MyField CONTAINS @UserName into the Notes FTIndex Query it returns the correct search results.

Further investigation and actually your work around will not work as a generalized case. If the field that you are querying is a multivalue fields and it contains several names from different  OU's you have no way of knowing if the CN/OU/O that it finds all relate to the same individual. I believe that the FTIndex lookup in SSJS is flawed and does not work in several different instances. I have found another instance wher I can not get the SSJS Search code does not work. I have a field in a document that may contain one or more roles, and I want to select documents where a user holds a role that is contained in the field, of course the user might possess more that one role as well. If I put the following in the Search property :

 var userRoles:Array = session.evaluate("@UserRoles");
qString =  "(FIELD ACCurentApprovers =  \"" + userRoles +"\")";
sessionScope.queryString = qString;
return qString;

I have no idea how to reasonably be able to documents when using the full distinguished name or a role. Really frustrating, hours of trial and error - mostly error.

 

  

 

(FIELD ACCurentApprovers = "[ACAdmin]"),(FIELD ACCurentApprovers = "[Marketing]")

it makes no difference if I use CONTAINS or EQUALS
It sure looks to me like the Search parses the

   

 

  

    

The actual 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal