Hi Matthias,
Thanks for replying. The problem is most of the time I don't know what is causing the errors. Like I said, the same action 9 times out of 10 works fine but every now and then for a seemingly random reason it fails with an error like above. I have resorted to writing lots of code in the system all over the place to try and code around these problems. The most common one I get is when a user clicks a workflow button that triggers querySave code to validate the doc in SSJS (rather than the validators you can define against each field in designer). If this function returns true, I then call a function to save the document. Originally the code started off with simply currentDocument.save() but in an attempt to find out what was going on I added logging and more complex code just to do the save.
I log EVERYTHING that the user does now to try and fault find, so this is a typical log entry when something has gone wrong:
(22-Feb-2012 09:42:30:375)... CURRENT UNID: D5933D802C2CA4FFC12579AC002FD630
(22-Feb-2012 09:42:30:640)... --> myUser.getCurrentDocument(): NotesXspDocument
(22-Feb-2012 09:42:30:640)... Problem Saving doc: Exception occurred calling method NotesXspDocument.getDocument(boolean)
null
(22-Feb-2012 09:42:30:640)... saveCurrentDocument returning: false
myUser is a managed bean about the user. The only recycling I do manually in the system is in the bean when it gets a record about the user to find out certain bits of information like their department, their roles, their team leader etc.
So the 4 entries above are generated by the following code:
1. The User clicks a workflow button and this calls the caseQuerySave function to validate. That has returned true so the function to save the document is called:
function saveCurrentDocument() {
try {
var success:boolean = false;
A: writeToLog("CURRENT UNID: " + myUser.setCurrentDocument());
var d:NotesXspDocument = myUser.getCurrentDocument();
B: writeToLog("--> myUser.getCurrentDocument(): " + typeof myUser.getCurrentDocument());
if (typeof d.getDocument(true)==null) {
sessionScope.informationMessage = "Problem saving the case: myUser.getCurrentDocument()" + " returned null. Please try saving again.";
}
else if (myUser.getShortName() == "") {
sessionScope.informationMessage = "Something has gone wrong with the myUser object, it's not set. Please try saving again.";
}
else {
writeToLog("Saving doc: " + d.getDocument().getUniversalID());
d.save();
success=true;
sessionScope.informationMessage = "Document saved...";
}
}
catch(e){
success = false;
C: writeToLog("Problem Saving doc: " + e);
sessionScope.informationMessage = "There was a problem saving the document for user " + myUser.getShortName() + ": " + e;
}
finally {
writeToLog("saveCurrentDocument returning: " + success.toString());
return success;
}
}
Line A above is the 1st message being written to the log. myUser.setCurrentDocument returns the UNID of the document that is being edited and has clearly worked as the UNID is displayed in the log message.
Line B - I'm not sure if this would prove that the myUser.getCurrentDocument() function has worked worked or not when the function is set to return a NotesXspDocument?
Line C is the error that is generated when d.save()
myUser.getCurrentDocument looks like this:
public DominoDocument getCurrentDocument(){
try {
myDoc = (DominoDocument)FacesContext.getCurrentInstance().getApplication().getVariableResolver().resolveVariable(FacesContext.getCurrentInstance(), "document1");
if (myDoc == null || (String)myDoc.getDocument(true).getUniversalID()=="") {
emailError("XPageUser.getCurrentDocument(): CurrentDocument is null - current User is " + shortName);
Log.writeLine("Getting Current Doc: " + setCurrentDocument());
throw new Exception("There was a problem getting the current document, please contact support.");
}
}catch(Exception e){
emailError("XPageUser.getCurrentDocument() Error: " + e.toString() + " - current User is " + shortName);
Log.writeLine("XPageUser.getCurrentDocument() Error: " + e.toString());
}finally {
return myDoc;
}
}
I don't ever receive the email to say the current document was null, yet the next time when it is used in the save document function further above, it generates an error.
This code is used many times a day without incident - is there anything in there that you can see that would be dodgy? and why would it work most of the time and just fail every now and then?
Really appreciate your help with this!