This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Sep 14, 2011, 11:24 PM
27 Posts
topic has been resolvedResolved

NotesDocument.save is not working - why?

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags: View NotesDocument save
  • Replies: 8
Hello everyone! 
 
Hopefully simple question:  I'm sort of new to Domino SSJ programming and do not understand why this is happening. I have this code:

var NotesDocument:doc = database.getView('myView').getDocumentByKey(unid);
doc.replaceItemValue('MyField','Y');
doc.save(true,false);
var doc2 = database.getView('vwLUDocLock').getDocumentByKey(unid);
var str = doc2.getItemValue('MyField');
print('MyField:'+str);

...which one would think would show that I changed 'MyField' to 'Y', but in the log file it always shows:

MyField:[N]

Can anybody tell me why is this not saving the value?  Do the square brackets denote it is an array?
 
Using the Lotus Notes client I can confirm that the data is not being changed.

Many thanks in advance for any advice!

Alex
Sep 15, 2011, 6:22 AM
178 Posts
Re: NotesDocument.save is not working - why?
 var str = doc2.getItemValueString('MyField');
or 
var str = doc2.getItemValue('MyField')[0]; 
Sep 15, 2011, 7:37 AM
54 Posts
Re: NotesDocument.save is not working - why?
I run into same kind of situation some time ago with Lotus Script (with DocumentContext). There I made some changes to the DocumentContext object (in agent). Relocated the document from database and any changes wasn't there. 
The solution was to set the documentContext object to null after the save.
 
I guess domino is caching something or trying to be just clever and not fetch the document again from the disc.
 
Have you tried to set the doc  as null before you fetch it again? Don't know does this help, but just a thougth anyway....
Sep 15, 2011, 1:11 PM
21 Posts
Re: NotesDocument.save is not working - why?
Set the document you just save to null  ( document = null) and retrieve the document again using the database object.
Sep 15, 2011, 4:13 PM
14 Posts
Re: NotesDocument.save is not working - why?
Hopefully this is a copy problem:
var NotesDocument:doc =
declres a variable named "NotesDocument" (which is dangerous) of class doc ;-)
 
 
Sep 15, 2011, 5:55 PM
27 Posts
Re: NotesDocument.save is not working - why?
 ...thanks everyone, I tried these suggestions but it frustratingly doesn't seem to be that simple.  It seems that if I qualify the datatype of the var, like so:
 
    var NotesDocument:doc = database.getView('MyView').getDocumentByKey(unid);
 
It returns an empty document (i.e. the fields I'm expecting in 'doc' are empty) but doc is not null.  However, this line: 
 
    var doc = database.getView('MyView').getDocumentByKey(unid);
 
...successfully returns the data I am expecting, but when I try to call: 
 
    doc.save(true,false); 
 
...I get the exception:   Exception occurred calling method NotesDocument.save(boolean, boolean)
 
Unfortunately that is all the details the logs offer.
 
Looking at the API a little closer I see that "getDocumentByKey" returns a "Document" object.  The "Document" object  (interface?) in turn DOES NOT have a method "save(boolean, boolean)" - it doesn't seem to have any "save" methods.  This may be why when I make the variable of type "NotesDocument", the "save" method works - but the data goes away.
 
Questions: 
  1. How do you change and re-save results from "View.getDocumentByKey()"?  I know it's possible with LotusScript**, so it should be in server side javascript, non?
  2. I assume that writing "var NotesDocument:doc ..." is declaring a variable 'doc' or type 'NotesDocument', correct?  WIll this automatically cast objects?
  3. Is it possible to create a "NotesDocument" from a "Document" object?  Is "Document" a super class of "NotesDocument"?
Sincere thanks again for any help!
 
Alex 
 
** - I am basing my javascript on working LotusScript from from a previous programmer (but am much more comfortable in javascript than LotusScript).
Sep 15, 2011, 6:35 PM
27 Posts
Re: NotesDocument.save is not working - why?
 ...I should add that I have searched on the exception and have found pages like this talking about an authentication problem:
 
http://lotusnotus.com/lotusnotus_en.nsf/dx/the-lesson-of-the-day-think-simple-while-debugging-xpages.htm 
 
...and I have verified that I am indeed correctly authenticated - so this is not the issue. 
Sep 19, 2011, 11:36 AM
3 Posts
Re: NotesDocument.save is not working - why?
I think you should use code like 
var doc:NotesDocument = ....  
that's all, you just had the wrong notation.
Sep 30, 2011, 8:48 PM
27 Posts
Re: NotesDocument.save is not working - why?
Thanks Mic Stone - I definitely had the syntax wrong.  That said, this wasn't actually the problem.
 
For those who get these following errors in the future: 
 
Exception occurred calling method NotesDocument.save(boolean) null
Exception occurred calling method NotesDocument.save(boolean,boolean) null
 
...what fixed it for me was how I retrieved the document.  Changing this:
 
var db:NotesDatabase = session.getDatabase(database.getServer(), database.getFilePath());
var doc = db.getView('MyView').getDocumentByKey(unid);
return doc;
 
...to this: 
 
var db:NotesDatabase = sessionAsSigner.getDatabase(database.getServer(), database.getFilePath());
var doc = db.getView('MyView').getDocumentByKey(unid);
return doc;
 
...fixed the problem! 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal