3

次のコードを持つエージェントがあります。

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イベントが発生したときに最後に実行されたとエージェントを確認しましたが、メッセージボックスや印刷出力が表示されません。

最初の質問は、なぜメッセージ ボックスが機能しないのかということです。2 番目の質問は、現在のドキュメントを取得するにはどうすればよいですか?

4

2 に答える 2

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

このパラメーターは、エージェントが ParameterDocID プロパティで使用できます。

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

于 2011-12-21T14:05:01.623 に答える
2

なぜ onChange からエージェントに移動したのかを知ることは役に立ちますが、やりたいことを実行する方法はいくつかあると思います。

あなたは式言語からエージェントを呼び出すと言いました-私はこの方法でエージェントを呼び出すメッセージボックスを表示することができました:

@Command([RunAgent];"CheckSupplierSpec")

もう 1 つのオプションは、エージェントを 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 Examples Databaseを学習することをお勧めします。彼の StatusBox の例は非モーダルですが、必要に応じてここでモーダルにするパラメータを見つけることができます。

于 2011-12-21T18:59:07.320 に答える