Getdocumentbykey in xPages

I have a problem using getdocumentbykey in ssjs in xPages. I’m trying to use it on the afterpageload event (orbeforepageload), to set an application scope variable. It never finds the relevant doc.

It works if I write the same in a lotusscript agent, so I don’t know whether it’s to do with the event I’m using it in or the way I’m using the methods.

The code is:

var n:NotesName = session.createName(@UserName());

var nab:NotesDatabase = session.getDatabase(session.getServerName(), “names.nsf”);

var v:NotesView = nab.getView(“($Users)”);

var nn:String = n.getCommon();

var doc:NotesDocument = v.getDocumentByKey(nn);

applicationScope.put(“mf”, doc.getItemValue(“MailFile”))

The error is that doc is nothing on setting the application scope, so it’s not finding the doc. It’s definitely there and as I say I can use the view to look up the doc using s.commonusername in lotusscript

Thanks for any help

Dan

Subject: getServerName

OK, what I’ve found is that session.getServerName returns blank on the Notes client - even though the database is on a server, not local

How do I get the actual servername and is this how it’s meant to work?

Subject: database.Server()

is database.Server() what you’re after?

Subject: Seems like the one

Sorry for taking so long to come back - yeah, database.getServer() is the one