FIELD Status := "Closed";
SELECT @All
エージェントを実行するには、URL が許可される箇所に OpenAgent URL コマンドを入力します。例えば次のようになります。
http://localhost/Web+test.nsf/Change+Status+to+Closed?OpenAgent
あるいは次のコードを含むアクションまたはホットスポットを実行します。
@Command([ToolsRunMacro]; "(Change Status to Closed)")
"This document is being opened from Notes at " + @Text(@Now)
フォームの WebQueryOpen イベントで「ChangeHeadText」エージェントを呼び出します。実行対象は、[None] です。次のようなコードになります。
@Command([ToolsRunMacro]; "ChangeHeadText")
ChangeHeadText には次の式が含まれています。このフォームを使用した文書がブラウザから開かれると、WebQueryOpen によって HeadText が変更されます。Notes クライアントから開かれると HeadText への変更はありません。
FIELD HeadText :=
"This document is being opened from a browser at " + @Text(@Now);
@All
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Set db = s.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument
Do While Not(doc Is Nothing)
doc.Status = "Closed"
Call doc.Save(False, True)
Set doc = dc.GetNextDocument(doc)
Loop
Print "<B>All Status fields set to 'Closed'</B>"
End Sub
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Set db = s.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument
Do While Not(doc Is Nothing)
doc.Status = "Closed"
Call doc.Save(False, True)
Set doc = dc.GetNextDocument(doc)
Loop
dbname$ = Evaluate("@WebDbName")
Print "[/" + dbname$ + "/Main+View?OpenView]"
End Sub
import lotus.domino.*;
import java.io.PrintWriter;
import java.util.Vector;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
DocumentCollection dc =
agentContext.getUnprocessedDocuments();
Document doc = dc.getFirstDocument();
while (doc != null) {
doc.replaceItemValue("Status", "Closed");
doc.save(false, true);
doc = dc.getNextDocument(doc);
}
PrintWriter pw = getAgentOutput();
Vector v = session.evaluate("@WebDbName");
pw.println("[/" + v.firstElement() + "/Main+View?OpenView]");
} catch(Exception e) {
e.printStackTrace();
}
}
}
http://localhost/Web+test.nsf/Change+Status?OpenAgent&Closed
次のようなコードになります。
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim arg As String, p1 As Long
arg = s.DocumentContext.Query_String(0)
p1 = Instr(arg, "&")
If p1 = 0 Then
Print "Need argument 'Open' or 'Closed'"
Exit Sub
Else
arg = Lcase(Mid$(arg, p1 + 1))
If arg <> "open" And arg <> "closed" Then
Print "Argument must be 'Open' or 'Closed'"
Exit Sub
End If
End If
arg = Ucase(Left$(arg, 1)) + Right$(arg, Len(arg) - 1)
Set db = s.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument
Do While Not(doc Is Nothing)
doc.Status = arg
Call doc.Save(False, True)
Set doc = dc.GetNextDocument(doc)
Loop
Print "<B>Status changed to "+ arg + " in all documents</B>"
End Sub