Question:
Is there a way to get the NoteID or UNID of the document I just created via an XPage?
For example, I want to fill out a form within an XPage and have it create a document (associated with a form) when I hit submit.
I want to know the NoteID or UNID of the note that was just created so I can have an agent run against it after the data source gets saved (after the submit)
Answer:
The easiest way to do this is to use the data source events. In this case, you could use the
querySaveDocument or
postSaveDocument event:
(In this example, the data source is named
"filedoc" )
Since the XPage is bound to a Domino document data source, you can use the data source
name in JavaScript inside these events to refer to it and get the NoteID or UNID (or call any of the Domino back-end classes)
The datatype of the document data source inside those events is a
NotesXspDocument object. You can use
.getDocument() to get to the back-end
NotesDocument object:
var doc:NotesDocument = DataSourceName.getDocument();
var sUNID = doc.getUniversalID();
var sNoteID = doc.getNoteID();
A couple of things to keep in mind:
- Newly created documents do not have a NoteID unless they've been saved to disk.
So, in the querySaveDocument() event, the NoteID is not available, but it is in the postSaveDocument() event.
- The UNID is available in the QuerySaveDocument() event though.