Question

I'm trying QueryNewDocumentEvent to do the following:

  1. Get a view from same database which has serial numbers document stored.
  2. Get the last document which is latest document
  3. Get the serial number in it and increase it by 1
  4. Create new serial number document and stored the increased serial number in it and save it.
  5. Assign the new serial number to a field in the current document.

The code works upto step 4 and give exception in step 5. If I run this code from postopen event it runs without any error but does nothing. Here is a code for QueryNewDocument.

var v:NotesView = database.getView('lastnumber');
var doc:NotesDocument = v.getLastDocument();
var dc1:NotesDocument = database.createDocument();
var tmp=doc.getItemValue('LastNumber')[0]+1;
dc1.replaceItemValue('Form','LastNumber');
dc1.replaceItemValue('LastNumber',tmp);
dc1.save(true,false,true)
currentDocument.setValue('ProjectNumber',"155,"+@Text(tmp));
currentDocument.setValue('LastNumber',@text(tmp)); 

I tried replacing currentDocument with document1 and gives the same exception. Logically anything wrong?

Was it helpful?

Solution

I can see two things that could be going wrong:

The first is that, depending on whether or not that's the exact code you're using, your second "@Text" call is written as "@text" and that will fail, since JavaScript is a case-sensitive language.

Additionally, I believe currentDocument won't be available in the queryNewDocument event (unless, I suppose, there was another document data source defined previously, in which case it might refer to THAT one instead). The "postNewDocument" event may be what you're looking for: that will run when you're creating a new document but AFTER the "currentDocument" variable is set to that doc.

"postOpenDocument", on the other hand, will likely only run if the action is specifically to open an existing document, not make a new one (it's not a direct analogue to PostOpen on a Form).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top