简体   繁体   English

获取NotesXSPDocument中的所有项目

[英]Get all items in NotesXSPDocument

In my Notes Database, I perform an audit when the document is saved. 在我的Notes数据库中,我在保存文档时执行审核。 Pretty easy in LotusScript. 在LotusScript中非常简单。 I grab the original document (oDoc) from the server, then in the document I modified (mDoc), I do a Forall loop that gets the names of each item; 我从服务器获取原始文档(oDoc),然后在我修改的文档(mDoc)中,我做了一个Forall循环,它获取每个项目的名称; forall item in mDoc.items. mDoc.items中的forall项。 Grab the same item from oDoc, execute a function with the new item as an argument that will run down a case statement that will see if its a field we care about. 从oDoc中获取相同的项目,使用新项目作为参数执行一个函数,该函数将运行一个case语句,该语句将查看它是否是我们关心的字段。 if so, I update a set of list values in the document with "When", "Who", "What field", and the "New Value". 如果是这样,我用“When”,“Who”,“What field”和“New Value”更新文档中的一组列表值。

I'm doing this in a server side script. 我在服务器端脚本中这样做。 In trying this, I discovered a couple of interesting things; 在尝试这个时,我发现了一些有趣的东西;

currentDocument is the NotesXSPDocument that contains everything that was just changed. currentDocument是NotesXSPDocument,包含刚刚更改的所有内容。

currentDocument.getDocument() contains the pre-change values. currentDocument.getDocument()包含更改前的值。 It also returns a NotesDocument which has the "items" field that I can run through. 它还返回一个NotesDocument,它包含我可以运行的“items”字段。

Thing is, I need something similar in the NotesXSPDocument. 事实是,我在NotesXSPDocument中需要类似的东西。 Is there a way in an iterative loop to grab the names and values of all items from there? 在迭代循环中有没有办法从那里获取所有项目的名称和值?

Here's the broken code. 这是破碎的代码。 (Currently it's walking through the NotesDocument items, but those are the old values. I'd rather walk down the XSP document items) (目前它正在浏览NotesDocument项目,但这些是旧的值。我宁愿走下XSP文档项目)

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 }
      }
    }
  }
}

You can get both versions of a document after submit - the original and the one with changed/new values : 您可以在提交后获得文档的两个版本 - 原始文档和具有更改/新值的文档:

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

changed: var changed_doc:NotesDocument = currentDocument.getDocument(true); 已更改: var changed_doc:NotesDocument = currentDocument.getDocument(true);

This way you can compare the items for changes. 这样您就可以比较更改项目。

But, there is a pitfall: after assigning "changed_doc" to currentDocument.getDocument(true) the "original_doc" has the changed values too because both variables point to the same document. 但是,存在一个缺陷:在将“changed_doc”分配给currentDocument.getDocument(true) ,“original_doc”也具有更改的值,因为两个变量都指向同一文档。 That's why we have to copy all items from currentDocument.getDocument() to a new temporary document first and only after get the changed values with currentDocument.getDocument(true) . 这就是为什么我们必须首先将currentDocument.getDocument()中的所有项目复制到新的临时文档,并且只有在使用currentDocument.getDocument(true)获取更改的值之后。 As an alternative you could read the original document from server like you do in LotusScript. 作为替代方案,您可以像在LotusScript中一样从服务器读取原始文档。

This is a code for detecting changed items as a starting point: 这是用于检测已更改项目的代码作为起点:

  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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM