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

发布于 2024-12-22 10:38:29 字数 2058 浏览 4 评论 0原文

我有一个具有以下代码的代理:

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

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

我现在已经创建了一个如上所述的代理,并且想要从 ui 中以 Lotus 脚本和 @formula 语言调用它。

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

我将代理创建为触发器,在事件 - 菜单选择上,目标:无,选项:共享。我确实收到了“Agent Ran”消息框。

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

第一个问题是,为什么消息框不起作用?第二个问题是如何获取当前文档?

I have an agent with the following code:

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

Previously it was ran within the onchange event of a field in a form.

I've now created an agent as above, and want to invoke it from the ui both in lotus script and @formula language.

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

I created the agent as trigger, on event - menu selection, target: none, options: shared. I do get the "Agent Ran" messagebox.

I've tried this however although checking the agent it says it last ran when the onchange event was fired i don't get any message boxes or print output.

The first question, is why isn't the messagebox working? the 2nd question is how can i get the current document?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄情伤 2024-12-29 10:38:29

问题在于,当您使用 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

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

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

The problem is that you lose context when you call an agent using the Run method. As the designer help states:

The user cannot interact directly with a called agent. User output goes to the Domino log.

You could try to pass the document's ID as a parameter to the run method instead:

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

That parameter is available to the agent in the ParameterDocID property:

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

天邊彩虹 2024-12-29 10:38:29

了解为什么将其从 onChange 移至代理会有所帮助,但我认为有一些方法可以做您想做的事情。

您提到从公式语言调用代理 - 我能够显示一个消息框,以这种方式调用代理:

@Command([RunAgent];"CheckSupplierSpec")

另一个选择是将您的代理作为 Java 代理。这使您可以访问即使由 NotesAgent.Run 调用也会显示的 Java UI 类。示例此处

如果您不想用 Java 重新设计整个代理,您可以使用 LS2J 来访问 Java UI 类。例如,您可以创建一个名为“Java Messagebox”的 Java 脚本库:

import javax.swing.JOptionPane;

public class JavaMessagebox {

    public void Messagebox (String message) {
        JOptionPane.showMessageDialog(null, message);
    }

}

然后从 LotusScript 代理中调用它,如下所示:

Use "Java Messagebox"
Uselsx "*javacon"
Sub Initialize
    Dim mySession  As JavaSession
    Dim myClass As JavaClass
    Dim myObject As JavaObject
    Set mySession = New JavaSession()
    Set myClass = mySession.GetClass("JavaMessagebox")
    Set myObject = myClass.CreateObject()
    myObject.Messagebox(|This is my Java messagebox!|)
End Sub

对于使用 Java AWT 组件(该组件使用操作系统的本机外观和感觉)的更复杂的示例,我建议学习 Julian Robichaux 的 LS2J 示例数据库。他的 StatusBox 示例是非模态的,但您可以找到使其成为模态的参数 此处

It would help to know why you moved it from onChange to an agent, but I think there are ways to do what you want to do.

You mentioned invoking the agent from formula language- I was able to display a Messagebox calling the agent this way:

@Command([RunAgent];"CheckSupplierSpec")

Another option would be doing your agent as a Java agent. This gives you access to Java UI classes that will display even if called by NotesAgent.Run. Example here.

If you don't want to rework the entire agent in Java, you can use LS2J to access the Java UI classes. For example, you could create a Java script library called "Java Messagebox":

import javax.swing.JOptionPane;

public class JavaMessagebox {

    public void Messagebox (String message) {
        JOptionPane.showMessageDialog(null, message);
    }

}

and then call it from a LotusScript agent like this:

Use "Java Messagebox"
Uselsx "*javacon"
Sub Initialize
    Dim mySession  As JavaSession
    Dim myClass As JavaClass
    Dim myObject As JavaObject
    Set mySession = New JavaSession()
    Set myClass = mySession.GetClass("JavaMessagebox")
    Set myObject = myClass.CreateObject()
    myObject.Messagebox(|This is my Java messagebox!|)
End Sub

For a more sophisticated example using a Java AWT component that uses the native look and feel of your operating system, I recommend studying Julian Robichaux's LS2J Examples Database. His StatusBox example is non-modal but you can find the parameter to make it modal here if needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文