Unable to reference a view in another database fro

2019-09-11 04:14发布

问题:

I have a repeat where the value loops through documents in the current database, these documents contain a database and view name. The repeat then opens the database and view and retrieves data from within them:

var dbOther:NotesDatabase = session.getDatabase(null, doc.getItemValueString("Database"));
if(dbOther != null){
    var lookupView:NotesView = dbOther.getView(doc.getItemValueString("ViewName"));
    var viewNav:NotesViewNavigator = lookupView.createViewNavFromCategory(key);
}       

This works fine on all browsers but if I view the xpage in the Notes Client I get the following error: Exception occurred calling method NotesDatabase.getView(string) null

I have tested that the dbOther variable is set by writing the Server and FilePath properties to a log. I checked that it could see the views by generating a loop using getViews and getAliases, again all view aliases were written to the log without an issue.

I have manually entered the view name in case the value was not being selected from the document correctly but received the same error.

Is there a way I can connect to a view in another database in XPiNC? I have found an XSnippet which allows you to dynamically add view data sources to your page, I think this may get around my problem but wanted to find out if there was an alternative solution before I re-write everything!

回答1:

Try some of these other ways of getting a handle on a database:

This one uses "" instead of the null parameter to indicate current server:

var dbOther:NotesDatabase = session.getDatabase("", doc.getItemValueString("Database"))

This one uses database.getServer() instead of the null parameter:

var dbOther:NotesDatabase = session.getDatabase(database.getServer(), doc.getItemValueString("Database"))

This one uses sessionAsSigner to get access to the database (instead of using the credentials of the current user):

var dbOther:NotesDatabase = sessionAsSigner.getDatabase(database.getServer(), doc.getItemValueString("Database"))

Are you using a Lotus Notes 8.5.3 client?



标签: xpages xpinc