0
votes

I currently have JavaScript dotted around my XPages - I would like to create a JavaScript library containing all this code and then just call the individual functions e.g. the press of a button. Here is an example of the code I would like in the JavaScript library:

// get the user document for that person
var myView:NotesView = database.getView("xpBenutzerInnen");
var query = new java.util.Vector();
query.addElement(sessionScope.notesName);
var myDoc:NotesDocument = myView.getDocumentByKey(query, true);

When I place this code in the library I get the error:

Syntax error on token ":", ; expected

I assume that the "var name:type" declaration is specific to XPages (this is what I found on creating JavaScript vars: http://www.w3schools.com/js/js_variables.asp) - I could just remove the type declaration and the code seems to run without any problems - I would like to better define the variable type though.

Is there any way that I can move the code out of the XPage but still keeping my typing?

Thanking you in advance Ursus

1

1 Answers

4
votes

You need to distinguish between client side JavaScript and Server side JavaScript. Your code is server side JS and should work in a Script library just as it does inside an XPage. Have you accidentally created a client side JS lib?

A few pointers: I try to make functions in a script library independent from global objects. Mostly the database object. This function works in a library just fine:

function getUserDocument(username:string, db:database) {
   var myView:NotesView = db.getView("xpBenutzerInnen");
   var query = new java.util.Vector();
   query.addElement(username);
   var myDoc:NotesDocument = myView.getDocumentByKey(query, true);
   myView.recycle();
   return myDoc;
}

Let me know how it goes