Passing information about UI objects to a java agent

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
    1. create a lotusscript agent called “save UI info in notes.ini” and with Trigger “Action menu selection” and Target “None”
      Option Public
      Option Declare
      
      Sub Initialize
      	
      	Dim w As New NotesUIWorkspace
      	Dim view As NotesUIView
      
      	Dim s As New NotesSession
      	Dim db As NotesDatabase
      	Dim agent As NotesAgent
      
      	Set view = w.Currentview
      	Call s.Setenvironmentvar("CurrentViewName", view.Viewname, false)
      	
      	Set db = s.Currentdatabase
      	Set agent = db.Getagent("(get UI info from notes.ini)")
      	Call agent.Run()
      	
      End Sub
      
    2. create a java agent called “get UI info from notes.ini” and with Trigger “Action list selection” and Target “None”
      import 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();
             }
         }
      }
      
  • second method: profile document
    1. create a lotusscript agent called “save UI info in profile document” and with Trigger “Action menu selection” and Target “None”
      Option Public
      Option Declare
      
      Sub Initialize
      	
      	Dim w As New NotesUIWorkspace
      	Dim view As NotesUIView
      
      	Dim s As New NotesSession
      	Dim db As NotesDatabase
      	Dim agent As NotesAgent
      	Dim docProfile As NotesDocument
      
      	Set view = w.Currentview
      
      	Set db = s.Currentdatabase
      	
      	Set 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
      
    2. create a java agent called “get UI info from profile document” and with Trigger “Action list selection” and Target “None”
      import 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();
             }
         }
      }
      

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
    1. create a lotusscript agent called “Pass notesuidocument to java agent” and with Trigger “Action menu selection” and Target “None”
      Option Public
      Option Declare
      
      Sub Initialize
      	
      	Dim w As New NotesUIWorkspace
      	Dim uidoc As NotesUIDocument
      
      	Dim s As New NotesSession
      	Dim db As NotesDatabase
      	Dim agent As NotesAgent
      	Dim doc As NotesDocument
      
      	Set uidoc = w.Currentdocument
      	Set doc = uidoc.Document
      
      	Set db = s.Currentdatabase
      
      	Set agent = db.Getagent("(get notesuidocument from lotusscript agent)")
      	Call agent.Run(doc.Noteid)
      	
      End Sub
      
    2. create a java agent called “get notesuidocument from lotusscript agent” and with Trigger “Action list selection” and Target “None”
      import 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.


Comments

One response to “Passing information about UI objects to a java agent”

  1. […] 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) […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.