Link to home
Start Free TrialLog in
Avatar of davinder101
davinder101

asked on

how to create an agent having lotus script code

hi,

i need to create an agent using c plus plus api that should have a lotus script code.

i got a sample from the api  (version 3.0) documents but it is not working.

Although

Agent.SetLotusScript(LotusScript); //this function seems to work
Agent.GetLotusScript(&LotusScript1); //as this function call is returning  the script text              
                                                           //that i have passed to it

but when i open the .nsf file

i am able to see a menu item having my newly created agent name "Importer"

but the lotus script code supplied to agent is not there.

can you tell me where i went wrong.

LNSTATUS st;	
 
LNLotusScript	LotusScript(scriptcode),LotusScript1;
LNAgent			Agent;	
 
#define AGENT_MANUAL        "My Importer"
LNString	Title(AGENT_MANUAL);
 
	// Clean up
	if(Db.AgentExists(Title))
		Db.DeleteAgent(Title);
 
	// Create shared Agent note
	Db.CreateAgent(Title, TRUE, &Agent);
 
	// Set comment
	//st = Agent.SetComment(Comment);
 
	// Enable
	st = Agent.SetIsEnabled(TRUE);
	st = Agent.SetLotusScript(LotusScript);
	// Set manual trigger                           
	st = Agent.SetAgentSchedule(LNAGENTSCHEDULE_MANUALLY_FROM_ACTIONS_MENU);
	// Save and close
	st = Agent.Save();
	st = Agent.GetLotusScript(&LotusScript1);
	LNString strabc = LotusScript1.GetSource();
	MessageBox(strabc);
 
	Agent.Close();
 
	Db.Close();

Open in new window

Avatar of mbonaci
mbonaci
Flag of Croatia image

It cannot be done like that. LotusScript must be previously saved inside Agent or ScriptLibrary using Notes UI.

Comment in notescpp samples samples\agents\agents.cpp file:
      // The problem with Lotus Script agents is that you can not use "raw"
      // Lotus Script source code. The reason is that internally Lotus Script
      // code is stored "decorated" with special headers which Notes UI uses
      // to properly render it. This means that Lotus Script code should be first
      // saved through Notes UI, and then it may be extracted for use elsewhere.
      // We'll use default agent with Lotus Script here as a storage facility.
      // In R5 script libraries may also be used for this purpose.
Avatar of davinder101
davinder101

ASKER


is there any way to all this using c plus plus api ?

or is there any way to run the lotus script code directly ?
If I understood right your problem is access to Domino Designer?
So you cannot make LS Agent manually in Designer as a template?

Java "lotus.notes" package has the same classes as LotusScript, only the class names are without Notes prefix (NotesDatabase in LS = Database in Java).
Java agents can be created using cpp without any access to Domino Designer.
All you need is any Java compiler to make java file into class file.

Would that be acceptable for you?
Here's the example from the same file I mentioned earlier:
//=======================================================================
//
//  FUNCTION:   AddJavaAgent
//
//  PURPOSE:    Add a Java Agent (executed from Menu) to the database.
//
//  DESCRIPTION:
//	This function adds a shared manual Agent named "Assign Hot Problems"
//	to the open database.  
//	
//	This Agent is Java based and will assign "Fire Fighters" as the 
//	Support Rep for those documents that have an "Open" Status and
//	"High" Priority. Java agents are supported for Notes Release 4.6
//	and later.
//
//	After creating this Agent, you can execute it 
//	by running the Notes workstation, opening the database, and selecting
//	this Agent from the "Actions" menu of the main view.  
//					       
//=========================================================================
void AddJavaAgent( LNDatabase &Db, const LNString &JavaFilesPath )
{
	LNAgent  Agent;
	LNString Title (AGENT_JAVA);
	LNString Comment ("Assign all hot problems (high priority) to Fire Fighters.");
	LNString Class ("HotAgent.class"); 
	LNString JavaFileName("HotAgent.class");
 
	// Clean up
	if(Db.AgentExists(Title))
		Db.DeleteAgent(Title);
 
	// Create Agent note
	Db.CreateAgent(Title, TRUE, &Agent);
 
	// Set comment
	Agent.SetComment(Comment);
 
	// Set Java Code
	LNText JavaFileNames;
	JavaFileNames << JavaFileName;
	Agent.CreateJavaCode(Class, JavaFilesPath, JavaFileNames);           
 
	// Enable
 	Agent.SetIsEnabled(TRUE);
 
	// Set schedule                          
	Agent.SetAgentSchedule(LNAGENTSCHEDULE_MANUALLY_FROM_ACTIONS_MENU);
 
	// Set documents option 
	Agent.SetAgentDocumentsOption (LNAGENTDOCUMENTSOPTION_ALL_IN_DB);
 
	// Enable
	Agent.SetIsEnabled(TRUE);
 
	// Save and close
	Agent.Save();
	Agent.Close();
 
}

Open in new window

yes,

can you tell how this java agent can be customized to import a dxl file to a .nsf file ?
Modify this agent that imports DXL from a file into a newly created database.

For help on Java Domino objects see here:
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/topic/com.ibm.help.domino.designer85.doc/DOC/H_USING_XML_WITH_JAVA_METHODS.html
import lotus.domino.*;
 
public class JavaAgent extends AgentBase {
 
  static DxlImporter importer = null;
 
  public void NotesMain() {
 
    try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();
 
      // Get current database
      Database db = agentContext.getCurrentDatabase();
      // Get DXL file
      String filename = "c:\\dxl\\exporteddb.dxl";
      Stream stream = session.createStream();
      if (stream.open(filename) & (stream.getBytes() >0)) {
        // Create new database - replace if it already exists
        Database newdb = session.getDatabase(null, "imported");
        if (newdb.isOpen())
          newdb.remove();
        DbDirectory dbdir = session.getDbDirectory(null);
        newdb = dbdir.createDatabase("imported", true);
        newdb.setTitle("Imported");
        // Import DXL from file to new database
        importer = session.createDxlImporter();
        importer.setReplaceDbProperties(true);
        importer.setReplicaRequiredForReplaceOrUpdate(false);
        importer.setAclImportOption(
          DxlImporter.DXLIMPORTOPTION_REPLACE_ELSE_IGNORE);
        importer.setDesignImportOption(
          DxlImporter.DXLIMPORTOPTION_CREATE);
        importer.importDxl(stream, newdb);
      }
      else
        System.out.println(filename + " does not exist or is empty");
 
    } catch(Exception e) {
      e.printStackTrace();
      
    } finally {
      // Print importer log
      try {
        System.out.println(importer.getLog());
      } catch(Exception e) {e.printStackTrace();}
    }
  }
}

Open in new window

>>All you need is any Java compiler to make java file into class file.
??

will this class file can be used with c plus plus api 3.0 ?

or i can use java generated .exe with c plus plus api 3.0 ?
Steps:
 1 - modify java code so that it suites your needs (imports the dxl into notes db as notesdocuments)
 2 - when you successfully compile that code you get .class file
 3 - the .class file is used to create an agent (same as the example AddJavaAgent, lines 26, 27 and 42)

If problems arise with step 2 you can attach .java file here (change extension to txt) and I'll compile it for you inside Domino designer...
hi

lotus script code that i want in my agent file is attached
please send me the .class file
also how can i generate it at my end using java ?
(i.e) do i need java api or something else to generate a .class file) ?
or what are the exact requirements to create lotus script agent using java .class file ?
script-code.txt
ASKER CERTIFIED SOLUTION
Avatar of mbonaci
mbonaci
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial


will this agent code stored in .class file will be execute to import or export the dxl file
if i call this method

agent.execute() ? using c plus plus api ?

what i have to do

if i have to run this agent code stored in .class file from my c plus plus code ?
I posted the code, didn't I?
It will do exactly what you provided in your LotusScript code.

1. To create it:
   - ALTER the c++ code I posted (in comment ID:24471347) to create the Java agent inside your database (using .class file). This function is the main one:

     LNSTATUS CreateJavaCode( const LNString &baseclassname, const LNString &codepath, const LNText &filenames, LNAgentJava *retjava )

     If it's not clear to you examine example and read topic "LNAgent class" in C++ API help database


2. To run it:
   - write some exe or dll function that will get the agent and call agent.execute().