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



Jan 3, 2012, 3:54 PM
170 Posts
topic has been resolvedResolved

getDocumentByKey do not find anything

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags:
  • Replies: 6
 I have a strange problem. I'm doing a simple getdocumentbykey
and I have tried several views in the database and I can't get any document. 
 
If I open the view and search for the same key the document is found 
 
The first column is sorted and the key is the same 100% sure. 
 
 
Anybody seen this before? 
 
/Fredrik 
Jan 3, 2012, 7:10 PM
170 Posts
Re: getDocumentByKey do not find anything
 An when I had logged out and in again I started to work again.
 
No error message on the server nothing. 
 
Strange, 
 
/Fredrik 
 
The Code that didn't work
 
var v=database.getView("(ByUNID)") // first column sorted with formula @Text(@DocumentUniqueID)
v.refresh()
var key=viewScope.UNIDKey // holds the UNID of a document 
var doc:NotesDocument=v.getDocumentByKey(key,true)
print(doc) 
 
Jan 3, 2012, 8:22 PM
261 Posts
Re: getDocumentByKey do not find anything
Fredrik,
 
Just wondering: why do you use a view for this? Wouldn't it be easier to just use database.getDocumentByUNID() ?
 
Mark
Jan 4, 2012, 5:58 AM
170 Posts
Re: getDocumentByKey do not find anything
 I started with that but that idn't work either. 
Jan 4, 2012, 7:57 AM
16 Posts
Re: getDocumentByKey do not find anything
Doing a lookup on a document unique id has never really worked. I have had issues with that since version 4.6 (web apps).
 
If you do want to use the unique id then add something to the key in the view and the key in your code, e.g. "k" + docunid. That has worked flawlessly for me. But I agree. If you do have the unique id it is way faster to get the document directly using the unique id without doing a view lookup. 
 
/John 
Jan 5, 2012, 8:44 AM
261 Posts
Re: getDocumentByKey do not find anything
That's true: if you do a lookup with a 32-character key Domino assumes it's a UNID and tries to retrieve the document by UNID, not by looking in the view index. This is also the reason why you can open a document using a URL with the syntax /<any-string>/<valid unid>
 
John's suggestions also works. Since a .getDocumentByUNID is extremely fast, you might consider trying that first (after removing any prefix you've added to the ID) and if that fails do a view.getDocumentByKey
 
Mark
Jan 5, 2012, 12:04 PM
1 Posts
Re: getDocumentByKey do not find anything
var db:NotesDatabase=session.getCurrentDatabase();
var ve:NotesView=db.getView(viewname);
var query = new java.util.Vector();
var key1= getComponent("ISO_FLD_TEnt").getValue();
var key2= getComponent("ISO_FLD_TEntSO").getValue();
var key4 = key;

query.addElement(@Trim(key1)+"*-*"+@Trim(key2)+"*-*"+@Trim(key3)+"*-*"+@Trim(key4));
var dc:NotesDocumentCollection = ve.getAllDocumentsByKey(query,true);
return dc.getCount();
 
try this..add key in vector.

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