从UI中通过lotusscript调用代理访问当前文档并显示消息框

Geo*_*ett 3 lotus-notes lotusscript agents

我有一个代理,代码如下:

Sub Initialize
    MessageBox "AgentStart"
    Print "AgentStart"

    Dim ws As New NotesUIWorkspace
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim vItemsBySupplierSpec As NotesView
    Dim Doc As NotesDocument
    Dim DocsWithSameSupplierSpec As NotesDocumentCollection
    Dim MatchingDoc As NotesDocument
    Set Doc = ws.CurrentDocument.Document

    If Len(Doc.ItemSupplierSpecification(0)) > 0 Then
        ' Check that this supplier specification isn't use anywhere else.'
        Set db = s.CurrentDatabase
        Set vItemsBySupplierSpec = db.GetView("vItemsBySupplierSpec")

        Set DocsWithSameSupplierSpec = vItemsBySupplierSpec.GetAllDocumentsByKey(Doc.ItemSupplierSpecification(0), True)
        Set MatchingDoc = DocsWithSameSupplierSpec.GetFirstDocument

        Dim ItemsString As String

        ItemsString = "The following items already use this supplier specification." + Chr(10) + Chr(10) + _
        "You should check whether you really want to raise another, or use the existing one." + Chr(10)


        While Not MatchingDoc Is Nothing
            ItemsString = ItemsString + Chr(10) + MatchingDoc.ItemNumber(0) + " - " + MatchingDoc.ItemDescription(0)
            Set MatchingDoc = DocsWithSameSupplierSpec.GetNextDocument(MatchingDoc)
        Wend

        If DocsWithSameSupplierSpec.Count > 0 Then
            Print ItemsString
            MsgBox ItemsString
        End If
    End If
End Sub
Run Code Online (Sandbox Code Playgroud)

以前它是在表单中的字段的onchange事件中运行的.

我现在已经创建了一个代理,并且想要在Lotus脚本和@formula语言中从ui调用它.

Dim s As New NotesSession
Dim db As NotesDatabase

Set db = s.CurrentDatabase

Dim CheckSupplierSpec As NotesAgent
Set CheckSupplierSpec = db.GetAgent("CheckSupplierSpec")

If CheckSupplierSpec.Run = 0 Then
    MessageBox "Agent Ran"
End If
Run Code Online (Sandbox Code Playgroud)

我创建了代理作为触发器,在事件菜单选择,目标:无,选项:共享.我确实得到了"Agent Ran"消息框.

我已经尝试过这个但是虽然检查代理它说它最后在onchange事件被触发时运行但我没有得到任何消息框或打印输出.

第一个问题,为什么消息箱不工作?第二个问题是我如何获得当前文件?

Ken*_*isa 5

问题是当您使用Run方法调用代理时会丢失上下文.正如设计师帮助说:

用户无法直接与被叫代理进行交互.用户输出转到Domino日志.

您可以尝试将文档的ID作为参数传递给run方法:

Dim ws as New NotesUIWorkspace
Dim s As New NotesSession
Dim db As NotesDatabase

Set db = s.CurrentDatabase

Dim CheckSupplierSpec As NotesAgent
Set CheckSupplierSpec = db.GetAgent("CheckSupplierSpec")

If CheckSupplierSpec.Run(ws.CurrentDocument.Document.NoteID) = 0 Then
    MessageBox "Agent Ran"
End If
Run Code Online (Sandbox Code Playgroud)

该参数可供ParameterDocID属性中的代理使用:

http://www-12.lotus.com/ldd/doc/domino_notes/rnext/help6_designer.nsf/Main?OpenFrameSet