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

davinder101Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbonaciCommented:
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.
0
davinder101Author Commented:

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

or is there any way to run the lotus script code directly ?
0
mbonaciCommented:
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

0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

davinder101Author Commented:
yes,

can you tell how this java agent can be customized to import a dxl file to a .nsf file ?
0
mbonaciCommented:
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

0
davinder101Author Commented:
>>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 ?
0
mbonaciCommented:
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...
0
davinder101Author Commented:
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
0
mbonaciCommented:
This is not "Rent A Coder". Still, I'm in a good mood today...

I translated your code to Java (which you should've done) and compiled the class file for you, but you'll need to parametrize the code or build it yourself.

To generate it at your end you need any kind of Java compiler (Javac, Jikes,...), but I suggest you use ECJ, which is included in Eclipse IDE (it's free).
 - download and install Eclipse Ganymede (for java)
 - open Eclipse
 - create new Java project
 - add new JVM of your current Lotus version (View - Preferences - Java - Installed JREs) as "Standard VM" type
 - add Notes.jar and LotusXSL.jar as external JARs (Project properties - Java Build Path - Libraries)
 - create new Class, name it JavaAgent and paste the code I provided
 - select Project - Build all
 - locate the class file in path defined in Project properties - Resource - Location


To answer your last question look at the code I posted first (once you have a class file it's trivial).
import lotus.domino.*;
 
public class JavaAgent extends AgentBase {
 
	static DxlImporter importer = null;
 
	public void NotesMain() {
 
		try {
			Session session = getSession();
			AgentContext agentContext = session.getAgentContext();
			Database db = agentContext.getCurrentDatabase();
			Stream stream = session.createStream();
			String strPath = "c:\\DXL\\mydxlfile.dxl";
	
			if( !stream.open( strPath ) ){
				throw new NotesException( NotesError.NOTES_ERR_FILEOPEN_FAILED, "Open failed" );
			}
	
			importer = session.createDxlImporter( );
			importer.setDocumentImportOption( DxlImporter.DXLIMPORTOPTION_REPLACE_ELSE_CREATE );
			importer.setDesignImportOption( DxlImporter.DXLIMPORTOPTION_REPLACE_ELSE_CREATE );
			importer.setReplicaRequiredForReplaceOrUpdate( false );
			
			importer.importDxl( stream, db );
	
			String noteid = importer.getFirstImportedNoteID();			
			Document doc = db.getDocumentByID( noteid );
			while( doc != null ){
				doc.putInFolder( "Test Folder" );
				noteid = importer.getNextImportedNoteID( noteid );
				doc = db.getDocumentByID( noteid );
			}       
 
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
}

Open in new window

JavaAgent.txt
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
davinder101Author Commented:


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 ?
0
mbonaciCommented:
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().
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.