1
votes

I get the error "Exception occurred calling method NotesDatabase.createDocument() null" for the following:

var db:NotesDatabase = session.getDatabase("", viewScope.targetDb);
if (db != null) {
   if(db.isOpen()){
   }else{
        db.open();
    }
} else {
}
var doc:NotesDocument = db.createDocument();

Comments: The database db is available and "open". The user has enough rights in the targetDb to create documents.

What is wrong?

I changed db.isOpen to db.isOpen(), according to Paul Stephen Withers tips. And now db.open() gives the error "Exception occurred calling method NotesDatabase.open() null" although that I can get, in viewScope variables, the server, FilePath, etc.

3
is this the full code? can you provide the full script as well as the full error message? can you output the title of db before you create the document using println(db.getTitle()); ?Michael Ruhnau
Do you use "/" instead of "\" in your path?Knut Herrmann
The targetDb equals a URL set in another place in the application, in other words "/" is used.Rolf Walter

3 Answers

2
votes

Change

var db:NotesDatabase = session.getDatabase("", viewScope.targetDb);

to

var db:NotesDatabase = session.getDatabase(currentDatabase.getServer(), viewScope.targetDb);

This works on the web as well as XPinC.

XPages isn't the same as formula, it doesn't like the empty string definition for the server name, which is contrary to the documentation which states (for the server parameter of NotesSession.getDatabase - javascript):]

The name of the server on which the database resides. Use null to indicate the session's environment, for example, the current computer

Using null or "" gives error 500, it would appear.

The code from the question will work, if :

  • the if block is removed entirely
  • the viewScope.targetDb variable has a properly specified notes database file path, which exists on the same server as the current database
  • the current user has access to the target database ( by the ACL ), with the Create Database right
  • the target database has a Maximum Internet name and password above Reader as per @Paul
1
votes

I suspect the cause is you're checking db.isOpen. You should check db.isOpen().

Worth bearing in mind is session.getDatabase(String, String) doesn't return null (unless you're using OpenNTF Domino API). It returns a Database object that is not open. So that if statement is irrelevant. Also best practice is to pass a server name to session.getDatabase() - you'll get a different outcome if the application is ever used in XPiNC with your current code.

Regardless of individuals' user access, "Maximum Internet name and password" on the Advanced tab of the ACL will override that. If maximum internet access is No Access, no one will be able to create documents. But I suspect that's not a factor here.

0
votes

Pro Tip -- Get the Debug Toolbar and use that to print out messages to the XPage debug toolbar to see what is going on and if your viewScope variable is being set. Also, learn to use the try catch block to catch your exceptions and print out the error message to the debug toolbar. You will find your issue that way. https://www.openntf.org/main.nsf/project.xsp?r=project/XPage%20Debug%20Toolbar