Lunatic Sol

IT Tips

ローカルで実行した LotusScript からサーバーコンソールに Print する

2003-12-13 02:28:06 | LotusScript
Messagebox や Print は良く使うと思いますが、ローカルで実行したときはダイアログやステータスバーに記録されます。また、サーバーで実行したときはサーバーコンソールに記録されます。これは当然の動作ですが、クライアント上で実行した処理をサーバーコンソール上に記録することはできないでしょうか?

だいたいそんなこと考えなくても NotesLog クラスを使えばスクリプトの実行を記録することができるので Msgbox や Print にこだわる必要はありませんし、そもそもなぜサーバーコンソールに記録する必要があるのでしょう?という意見もあるかもしれません。でも、時にはコンソール上でログの時系列通りに記録してもらった方がトラブルシューティングに役に立つケースもあるかもしれませんよね。そんな「もしも」の時に使えるかもしれないちょっとした方法を考えてみました。RunOnServer メソッド (NotesDatabase クラス) を使います。

Sub Initialize
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim agent As NotesAgent

    Set db = s.CurrentDatabase
    Set agent = db.GetAgent("printAgent")
    If agent.RunOnServer() <> 0 Then
Print "失敗: エージェントが実行できませんでした"
End Sub


printAgent エージェント

Sub Initialize
    Print "Local agent is executed !"
End Sub


上記の例は本当に単純に Print を実行するだけのエージェント printAgent (2つめのサンプル) を作成し、それを RunOnServer メソッドで Call する (最初のサンプルがローカルで実行するスクリプト) だけのものです。これでローカルエージェントの実行時にサーバーコンソールに Print を流すことができます。でも、printAgent の内容が Static になってしまいメリットがありません。

RunOnServer メソッドは引数に Note ID を String 型で受け取ることができるので、Notes 上で作業中の Note ID を RunOnServer メソッドに渡すことでその Note ID をベースにした情報をコンソールに Print することができます。以下の例では Note ID で取得した NotesDocument オブジェクトを使って UNID をコンソールに Print しています。こうすると少しは用途が出てくるでしょうか?

Sub Initialize
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim agent As NotesAgent
    Dim ws As New NotesUIWorkspace
    Dim uidoc As NotesUIDocument
    Dim doc As NotesDocument

    Set db = s.CurrentDatabase
    Set agent = db.GetAgent("printAgent")
    Set uidoc = ws.CurrentDocument
    Set doc = uidoc.Document

    If agent.RunOnServer(doc.NoteID;) <> 0 Then
Print "失敗: エージェントが実行できませんでした"
End Sub


printAgent エージェント

Sub Initialize
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim agent As NotesAgent
    Dim doc As NotesDocument
    Dim docId As String

    Set db = s.CurrentDatabase
    Set agent = s.CurrentAgent
    docId = agent.ParameterDocID
    Set doc = db.GetDocumentByID(docId)

    'ここに処理したい内容を書く

    Print "UNID=" + doc.UniversalID
End Sub

最新の画像もっと見る