The lotus java agents don’t have classes to manage the UI objects, such as in LotusScript with the classes NotesUIDocument or NotesUIView.
It’s true that you can find several info about the Notes Client Java UI API in internet, but these classes are not officially supported.
In this post I explain 3 ways to obtain the currently open view or document inside an agent java.
You take advantage of the LotusScript UI classes that can easily manage the UI objects, and you pass them to the java agent using the variables in the notes.ini or a profile document or a notes document.
- first method: notes.ini
- create a lotusscript agent called “save UI info in notes.ini” and with Trigger “Action menu selection” and Target “None”
1234567891011121314151617181920Option PublicOption DeclareSub InitializeDim w As New NotesUIWorkspaceDim view As NotesUIViewDim s As New NotesSessionDim db As NotesDatabaseDim agent As NotesAgentSet view = w.CurrentviewCall s.Setenvironmentvar("CurrentViewName", view.Viewname, false)Set db = s.CurrentdatabaseSet agent = db.Getagent("(get UI info from notes.ini)")Call agent.Run()End Sub - create a java agent called “get UI info from notes.ini” and with Trigger “Action list selection” and Target “None”
1234567891011121314151617181920import lotus.domino.*;public class JavaAgent extends AgentBase {public void NotesMain() {try {Session session = getSession();AgentContext agentContext = session.getAgentContext();String viewName = session.getEnvironmentString("CurrentViewName", false);Database db = session.getCurrentDatabase();View view = db.getView(viewName);System.out.println(view.getName());} catch(Exception e) {e.printStackTrace();}}}
- create a lotusscript agent called “save UI info in notes.ini” and with Trigger “Action menu selection” and Target “None”
- second method: profile document
- create a lotusscript agent called “save UI info in profile document” and with Trigger “Action menu selection” and Target “None”
12345678910111213141516171819202122232425Option PublicOption DeclareSub InitializeDim w As New NotesUIWorkspaceDim view As NotesUIViewDim s As New NotesSessionDim db As NotesDatabaseDim agent As NotesAgentDim docProfile As NotesDocumentSet view = w.CurrentviewSet db = s.CurrentdatabaseSet docProfile = db.getProfileDocument("myProfile", s.UserName)Call docProfile.Replaceitemvalue("CurrentViewName", view.Viewname)Call docProfile.Save(true, false, false)Set agent = db.Getagent("(get UI info from profile document)")Call agent.Run()End Sub - create a java agent called “get UI info from profile document” and with Trigger “Action list selection” and Target “None”
123456789101112131415161718192021import lotus.domino.*;public class JavaAgent extends AgentBase {public void NotesMain() {try {Session session = getSession();AgentContext agentContext = session.getAgentContext();Database db = session.getCurrentDatabase();Document profileDocument = db.getProfileDocument("myProfile", session.getUserName());String viewName = profileDocument.getItemValueString("CurrentViewName");View view = db.getView(viewName);System.out.println(view.getName());} catch(Exception e) {e.printStackTrace();}}}
- create a lotusscript agent called “save UI info in profile document” and with Trigger “Action menu selection” and Target “None”
In both cases, launch the lotusScript agent from a view (Actions menu), and the name of the view is displayed on the java console.
You can also pass a document noteID to the java agent as a parameter of the method “Run” of the lotusscript class NotesAgent.
In the following example you see as you can pass the backend document corresponding to the currently open document.
- third method: notes document as parameter of Run method
- create a lotusscript agent called “Pass notesuidocument to java agent” and with Trigger “Action menu selection” and Target “None”
12345678910111213141516171819202122Option PublicOption DeclareSub InitializeDim w As New NotesUIWorkspaceDim uidoc As NotesUIDocumentDim s As New NotesSessionDim db As NotesDatabaseDim agent As NotesAgentDim doc As NotesDocumentSet uidoc = w.CurrentdocumentSet doc = uidoc.DocumentSet db = s.CurrentdatabaseSet agent = db.Getagent("(get notesuidocument from lotusscript agent)")Call agent.Run(doc.Noteid)End Sub - create a java agent called “get notesuidocument from lotusscript agent” and with Trigger “Action list selection” and Target “None”
1234567891011121314151617181920import lotus.domino.*;public class JavaAgent extends AgentBase {public void NotesMain() {try {Session session = getSession();AgentContext agentContext = session.getAgentContext();Database db = session.getCurrentDatabase();Agent agent = agentContext.getCurrentAgent();Document doc = db.getDocumentByID(agent.getParameterDocID());System.out.println(doc.getNoteID());} catch(Exception e) {e.printStackTrace();}}}
This last example must be run from an open document and shows the noteID on the java console.
The java agent can’t modify the document on the screen but can modify the backend document.
- create a lotusscript agent called “Pass notesuidocument to java agent” and with Trigger “Action menu selection” and Target “None”
One reply on “Passing information about UI objects to a java agent”
[…] the path to the excel file and the name of the lotus view are hardcoded as “final String” but you can pass them as parameters to the java agent (see the post Passing information about UI objects to a java agent) […]