Jan 3, 2012, 10:54 AM
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? 
Jan 3, 2012, 2: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. 
The Code that didn't work
var v=database.getView("(ByUNID)") // first column sorted with formula @Text(@DocumentUniqueID)
var key=viewScope.UNIDKey // holds the UNID of a document 
var doc:NotesDocument=v.getDocumentByKey(key,true)
Jan 3, 2012, 3:22 PM
261 Posts
Re: getDocumentByKey do not find anything
Just wondering: why do you use a view for this? Wouldn't it be easier to just use database.getDocumentByUNID() ?
Jan 4, 2012, 12:58 AM
170 Posts
Re: getDocumentByKey do not find anything
 I started with that but that idn't work either. 
Jan 4, 2012, 2: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. 
Jan 5, 2012, 3: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
Jan 5, 2012, 7:04 AM
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;

var dc:NotesDocumentCollection = ve.getAllDocumentsByKey(query,true);
return dc.getCount();
try this..add key in vector.