xpages保存文档时运行脚本

时间:2014-10-30 04:21:07

标签: save xpages

xpages包含SAVE按钮。 xpages还包含InternetAddres字段。 当用户单击SAVE按钮时,需要先检查names.nsf - 如果在names.nsf视图中找不到InternetAddress值,则保存成功“($ Users)” - 如果在names.nsf中找到InternetAddress值,则保存失败“($ Users)”

如何编写脚本来做到这一点?

这是脚本的LotusScript版本:

Set namesview = namesdb.GetView( "($Users)" )
Set namesdoc = namesview.GetDocumentByKey( Lcase(doc.CurrentInternetAddress( 0 ) ), True )
If ( namesdoc Is Nothing ) Then '-- Create New Doc

如何继续使用xpages?

2 个答案:

答案 0 :(得分:5)

最新版本的OpenNTF Domino API为View类添加了checkUnique()方法。它需要两个参数,第一个是检查视图的键(例如字符串或字符串列表),第二个是当前文档。毕竟,如果您正在检查预先存在的文档,那么您不希望因为它在视图中找到此文档而失败。

因此,假设CurrentInternetAddress是单个值字段,则代码为:

function continueWithValidUser(namesDB, doc) {
    var success = false;
    try {
       var view = namesDB.getView("($Users)");
       success = view.checkUnique(doc.getItemValue("CurrentInternetAddress"),doc);
    } catch (e) {
      print(e.message);
    }        
    return success;
}

OpenNTF Domino API会回收Domino对象的所有句柄,因此不需要进行recycle()调用。

答案 1 :(得分:0)

在您的数据源中是querySave事件。你在那里写JS。它几乎是相同的代码。只需使用{}和;

说明:

  • 当有多个地址簿时,您的应用会中断,因此您需要使用速度非常快的@NameLookup并检查所有地址簿。
  • 除非您需要文档getEntry比getDocument
  • 更快

在SSJS中你的功能如下:

function continueWithValidUser(namesDB, addressCandidate) {
    var success = false;
    try {
       var view = namesDB.getView("($Users)");
       var doc = view.getDocumentByKey(addressCandidate);
       success = (doc != null);
       doc.recycle();
       view.recycle();
    } catch (e) {
      print(e.message);
    }        
    return success;

}

应该做的伎俩

相关问题