0
votes

In a Java class in my XPages application, I'm trying to get a handle on a Notes Document in a Notes View. The Notes View contains several Notes Documents. To get the Notes Document I want, I use 2 keys. This produces an error. If I use just one key, the first Notes Document in the Notes View is returned. The Notes View contains two sorted columns. The first column contains the empLang value, the second column contains the templateType value. Here is my code:

    String empLang = "en";
    String templateType = "C";
    Database dbCurr = session.getCurrentDatabase(); 
    String viewName = "vieAdminTemplates" + empLang;
    View tview = dbCurr.getView(viewName);
    Vector viewKey = new Vector();
    viewKey.addElement(empLang);
    viewKey.addElement(templateType); // this line causes the code to fail
    Document templateDoc = tview.getDocumentByKey(viewKey);

What could be the cause of this problem?

3
Offhand, I think that .getDocumentByKey only works on the first sorted column. You might want to use the Database.Search instead.Steve Zavocki
getDocumentByKey etc in Java work with multiple columns, see intec.co.uk/…Paul Stephen Withers
Your example above works perfect for me. Is your import for Vector import java.util.Vector; too?Knut Herrmann

3 Answers

1
votes

A couple of ideas

1) You could concatenate the key into a single column since you said that worked. Something like 'en~C'

2) You could use the database.search method where you include a string of formula language that isolates the document you want. It returns a collection, and then you pull the document from there.

1
votes

getDocumentByKey works with multiple columns. There's a known problem with doubles, but you're not hitting that there. One thing that stands out is the second column is just a single letter. That could be considered as a Char instead of a String, either when you do addElement or by the view.

I'd recommend debugging out what data type they are. viewKey.get(1).getClass().getName() I think gives you the class it's stored as. Doing the same for the View Column value.

When you say it causes the code to fail, how does it fail? Does it just not return anything or throw an error?

My next step would be to try testing it where the View and the Vector contain more than one character, e.g. "CC", to help check if there's an underlying issue with Java getDocumentByKey and single characters.

0
votes

I'm very sorry. The problem here is that the view name in the code is incorrect. There is a view "vieAdminTemplates" but it does not have a second column containing the value "C". With the correct view, the code works fine. Thanks for taking the time to respond to my question.