Get all items in NotesXSPDocument

In my Notes database, I audit when I save a document. Pretty easy in LotusScript. I take the source document (oDoc) from the server, and then in the document I modified (mDoc), I make a Forall loop that gets the names of each element; forall item in mDoc.items. Take the same element from oDoc, execute a function with the new element as an argument that will work with the case argument, which will see if this field is of interest. if so, I am updating the set of list values ​​in the document with When, Who, Which Field, and New Value.

I am doing this server side script. After trying this, I found a couple of interesting things:

currentDocument is a NotesXSPDocument document containing everything that has just been modified.

currentDocument.getDocument () contains pre-replacement values. It also returns a NotesDocument in which there is a “items” field that I can execute.

The thing is, I need something like this in NotesXSPDocument. Is there a way in an iterative loop to grab the names and values ​​of all elements from there?

Here is the broken code. (He is currently looking at NotesDocument elements, but these are old values. I would rather go on to elements of an XSP document)

function FInvoice_beginAudit() {
  var original_doc:NotesDocument = currentDocument.getDocument();
  var oItem:NotesItem;

  var oItems:java.util.Vector = original_doc.getItems();
  var iterator = oItems.iterator();
  while (iterator.hasNext()) {
    var oItem:NotesItem = iterator.next();
    item = currentDocument.getItemValue(oItem.getName());
    if (oItem == undefined) {
      var MasterItem =  ScreenAudit(doc,item,True)
      if (MasterItem) { return true }
      } else {
      if (item.getValueString() != oItem.getValueString()) {
        var MasterItem =  ScreenAudit(doc,Item,True);
          if (MasterItem) { return true }
      }
    }
  }
}
+4
source share
1 answer

You can get both versions of the document after sending - the original and the changed / new values :

: var original_doc:NotesDocument = currentDocument.getDocument();

: var changed_doc:NotesDocument = currentDocument.getDocument(true);

.

: "changed_doc" currentDocument.getDocument(true) "original_doc" , . currentDocument.getDocument() currentDocument.getDocument(true). , LotusScript.

:

  var original_doc:NotesDocument = database.createDocument();
  currentDocument.getDocument().copyAllItems(original_doc, true);
  var changed_doc:NotesDocument = currentDocument.getDocument(true);
  var oItems:java.util.Vector = original_doc.getItems();
  var iterator = oItems.iterator();
  while (iterator.hasNext()) {
    var oItem:NotesItem = iterator.next();
    var itemName = oItem.getName();
    var cItem:NotesItem = changed_doc.getFirstItem(itemName);
    if (cItem.getText() !== oItem.getText()) {
        print("changed: " + itemName);
    }
    oItem.recycle();
    cItem.recycle();
  }
  original_doc.remove(true);
  original_doc.recycle();
+6

Source: https://habr.com/ru/post/1538432/


All Articles