The lesson of the day: Think simple while debugging XPages!
However, sometimes error messages make me crazy! Here is an example...
I am developing an XPages project and I worked on SSJS persistence and scope issues a lot.
Yesterday, in the middle of night, I had a stupid problem in my code.
function getDoc(someParams) {
// ... do something ... //
return someDoc;
}
function setSomeValue(value) {
doc=getDoc(someParams);
doc.replaceItemValue("someField", value);
doc.computeWithForm(false, false);
if(! doc.save(false, false)) {
// ... do some logging stuff ... //
}
}
It's a simple code. Get some document and set some fields and save... However, it sometimes throws an error like this:
Error while executing JavaScript action expression
Script interpreter error, line€, col=26: [TypeError] Exception occurred calling method NotesDocument.save(boolean, boolean) null
The error is coming from "doc.save()" method. But the error message is interesting. There is a "TypeError" here. So I put 'print's everywhere in my code to determine if 'doc' object is fine. No solution... It also says null. Again a number of 'print's, no hope! I removed functions and put my code directly into a button, no hope! It doesn't work...
Then I noticed the problem. I was testing the code with anonymous user and it doesn't have authorization!!! The error should be "You are not authorized to do that". Or maybe it should not throw an error and just return false (I am not sure about the last one because there wouldn't any chance to know exact problem in this case).
Dealing with high level problems like SSJS persistence and scope issues have prevented me to think simple.
Anyway, the lesson of the day is 'Think simple while debugging. Eliminate the most obvious reasons before ripping your nice code...
Comments (6)
@Tom,
Thank you... The largest portion of my visitors are coming from Google and this is a still-popular thread :)
I know this is an old thread, but just because it's so high on the rankings for a search on this problem I thought I'd add my experience in anyway.
Had the same problem (initially) with no access, but the problem wouldn't go away. After a half a day digging around my code, it turned out that the problem was a single field in the document that had a null pushed into it.
For some reason, it happily poked the null into the field and then failed to save several lines south.
The really odd thing (given this was a save operation on a new document) was the stack trace showed 'Note cannot be deleted' as a key error message.
Anyway, one more thing to check for anyone finding a similar problem.
In our XPages class I gloss over the ACL and thus the deletion of a record fails (default no delete). So participants struggle a little but sooner or later figure it out. That struggle anchors the attention to access rights.
ha!
I was getting some nulls (thanks Tom) -- got those dealt with....
then still problem even after checking access control all looked good -- but then aha! turned out to be, maximum internet access on the database was set to reader! Had to raise that.
Thanks for clues everybody!