I would like the following agent to run onclick of a button, the agents job is to check if the user wants a document(in this case a Journal Entry) to be date repetetive. So I am trying to create multiple documents at once. I had a simular Lotusscript running in the Notes Application which seemed to work fine but I dont know how to run it on my Xpage. Code:
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim UIdoc As NotesUIDocument
Dim doc As NotesDocument
Dim Workspace As New NotesUIWorkspace
Set db = session.CurrentDatabase
Set UIdoc = workspace.CurrentDocument
Dim Radio As String
Dim String1 As String
Dim Counter As Integer
Print("Repeat Agent Triggered and Variables Initialized")
String1 = UIdoc.FieldGetText("SubjectTX")
Radio = UIdoc.FieldGetText( "RepeatValueTX" )
Dim ret As Variant
Dim Newdate As New NotesDateTime(UIdoc.FieldGetText("DiaryDateDT"))
Print(Radio)
Print(String1)
Print("Select Case...")
Select Case Radio
Case "Day":
Print("Case Day in use")
For Counter = 1 To 7
Call Newdate.AdjustDay( 1 )
Set doc = db.CreateDocument
doc.SubjectTX = "Day Revision " + String1
doc.DiaryDateDT = NewDate
Call doc.Save( True, True )
Next
Case "Week":
Print("Case Week in use")
For Counter = 1 To 4
Call Newdate.AdjustDay( 7 )
Set doc = db.CreateDocument
doc.SubjectTX = "Week Revision:" + String1
doc.DiaryDateDT = NewDate
Call doc.Save( True, True )
Next
Case Else:
Print("No Case or Saving and Closing")
End Select
Print("exited switch, Saving and Closing now")
Call UIdoc.Save()
Call UIdoc.Close()
End Sub
The Agent is set to "Allow restricted operations" , "Run as Web user" , Target:none, "Agent List selection".
The Javascript supposed to execute the Agent
database.getAgent("Repeatagent").run()
maybe I am missing something essential here, if there is a better way to do this please let me know!
I am fairly new to notes and sort of bunched this together from the help menu so if you have a solution please try to explain very extensive.
Thank you
I'd recommend to translate this agent to a Java Bean and call it directly from your Xpage's querysave event.
If you still like the lotusscript agent, then you need to change the UI classes to backend (NotesUIDocument -> NotesDocument) as you do not have access to NotesUIWorkspace in backendagent. In this case, have a look at passing the documentcontext to an agent