Solved

Running Lotes Notes agent from .NET

Posted on 2006-10-27
19
1,189 Views
Last Modified: 2013-12-18
Hi,

I'm referencing domobj.tlb from my Visual Studio project to access LotusNotes objects. I am getting an "Object reference not set to an instance of an object" when I try to do notesAgent.RunOnServer(documentId). Please refer to the code below:

01      NotesSession ns = new NotesSessionClass();
02      ns.Initialize(currentPassword);      
03      NotesDbDirectory dbDir = ns.GetDbDirectory(ServerName);
04      NotesDatabase notesDatabase = dbDir.OpenDatabase(DatabaseName, false);
05      NotesDocument ndoc = notesDatabase.CreateDocument();
06      ndoc.ReplaceItemValue("Form", FormName);
07      ndoc.ReplaceItemValue("EmailAddress", "abc@xyz.com");
08      ndoc.Save(true, false, false);
09      NotesAgent agent = notesDatabase.GetAgent(AgentName);
10      agent.RunOnServer(ndoc.NoteID);

The program doesn't have any problem in saving the parameter document in step 8. So connection, username / password and other things are not the issue. When it hits step 10, it's throwing the standard .NET NullReferenceException "Object reference not set to an instance of an object". BTW, I am using C# but I don't believe the result from VB.NET would be any different.

I am kind of stuck here. Your expert opinion will be highly appreciated. I'm giving this question 500 points as I've not made any advance in past couple of days and the deadline is very near.

Thanks,
Ram
0
Comment
Question by:rpdash
  • 7
  • 5
  • 3
  • +3
19 Comments
 
LVL 63

Expert Comment

by:SysExpert
ID: 17822098

04     NotesDatabase notesDatabase = dbDir.OpenDatabase(DatabaseName, false);
why twice  NotesDatabase . I think only 1 is needed

 
I hope this helps !
0
 
LVL 63

Expert Comment

by:SysExpert
ID: 17822154
My first comment may not be relevant :

I would print out the agent name since I do not see it defined anywhere
I would also check that the agent actually exists after step 09
also you might try

agent.RunOnServer(ndoc.NoteID(0));

Since most fields allow multiple values in an array.

I hope this helps !
0
 

Author Comment

by:rpdash
ID: 17822173
The first "NotesDatabase" is the class name which I am instantiating. The second "notesDatabase" is the name of the instantiated object. This code is in C# which is case sensitive. My code could well have been
04     NotesDatabase ndb = dbDir.OpenDatabase(DatabaseName, false);
05     NotesDocument ndoc = ndb.CreateDocument();
06     ndoc.ReplaceItemValue("Form", FormName);
07     ndoc.ReplaceItemValue("EmailAddress", "abc@xyz.com");
08     ndoc.Save(true, false, false);
09     NotesAgent agent = ndb.GetAgent(AgentName);
10     agent.RunOnServer(ndoc.NoteID);
and it would not have made any difference.

Thanks,
Ram
0
 

Author Comment

by:rpdash
ID: 17822213
Hi SysExpert,

Thanks for your response. However, please bear in mind that I am referencing a COM object. So lots of stuff that can are available in Lotus Scripts is not available here. ndoc.NoteID is a string and not an array. It's returning with the actual ID of the document created. I've also verified that the agent exists. I've supplied only relevant portions of my code. The parameter list of the method includes the following:

string currentPassword¸ string strNotesIDFile, string strPassword, string ServerName, string DatabaseName, string FormName, string EmailAddress, string AgentName

Thanks,
Ram
0
 
LVL 63

Expert Comment

by:SysExpert
ID: 17822240
Can you check the Agent log on the server for any errors ?

Is the agent expecting a parameter ndoc.NoteID.

Do you have the proper permissions to run an agent on the Server ?

Have you tried a local agent to see what happens ?

I hope this helps !

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17822270
I assume that in your step 09, the agent cannot be found, hence agent equals zero/null. Can you add one line that references a property of agent, or some other assertion that agent isn't null?
0
 

Author Comment

by:rpdash
ID: 17822327
SysExpert, sjef_bosman,

1. The database log shows a session has been accessed. But the database log is silent about the agent. The agent log is empty. It seems that the agenat has not run at all.
2. Yes, the agent expects the parameter document.
3. Yes, the ID I am using is a manager and has all the security permissions.
4. All our agents are on server.
5. In step 09, I can watch the agent and can view it's properties. So no, the agent is NOT NULL. However, when I invoke RunOnServer (step 10), I immediately get an exception without the agent being run.

Thanks,
Ram
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17822401
You're thorough... I suppose you also watched ndoc to see that it has a NoteID property (and not NoteId)? After the Save, I mean? IMHO, either agent or ndoc is null.

Other option:
09     NotesAgent agent = notesDatabase.GetAgent(AgentName);
10     String noteID= ndoc.NoteID;
11     agent.RunOnServer(noteID);

Which line makes it stop now?

0
 

Author Comment

by:rpdash
ID: 17822777
Hi sjef_bosman,

Thanks, yes, I've verified that ndoc has a NoteID which matches with the document ID in databse. It failes on line 11. Neither ndoc nor agent is null. So it's basically something in RunOnServer method which throws an exception (prior to actually running the agent). So I guess my question is, what information it needs to see in the NotesAgent object? The exception doesn't tell much, neither the stacktrace goes deep within.

Thanks,
Ram
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17822849
Can you leave out the noteID, and call agent.RunOnServer without any parameters? Oh forget it, it won't make any difference...

And when you call agent.Run() ??

I suppose (and hope) that the agent's properties in the Designer will allow it to run in the background? It must be a scheduled agent, run never will do. Can you ask someone to call the same agent from LotusScript, also with RunOnServer, to make sure it does run at all?
0
 

Author Comment

by:rpdash
ID: 17822903
The COM reference doesn't have a parameterless method signature. So I can't try RunOnServer without NoteID. I've tried Run(NoteID) with no avail. Again, the parameterless method signature is not available for "Run" as well. Yes, the agent can be run within LotusScript with RunOnServer without any issues. This agent is not a scheduled agent. It must be invoked by my process to complete the action (based on my parameter document).
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17823205
Instead of the NoteID parameter to indicate your document, you could do it the difficult way, using an additional field and a view that selects documents with that field and a specific value. You might call agent.RunOnServer(""). But that's not the issue.

I think I'll use the night (it's 01:22 over here) for some reflection... ;-)
0
 

Author Comment

by:rpdash
ID: 17824682
Hi sjef_bosman,

You've been very helpful. I've thought of different ways to adress my issue. For example, I can save the document only and not run the agent from .NET. I can make the agent a scheduled agent which will pick up the documents and act upon it. But that's not the point. We're developing a model which will be used by lot of different applications and at some point or the other I'll be required to run the agent from .NET passing a parameter document. Proposion does it (I've used Proposion to pass in the emailaddress parameter to the agent and it runs from .NET but my company would not buy the license), so why can't we?

If you've access to .NET and Notes tools and more importantly some spare time, you can try my code. If you're successful, I can blame it on our environment :-)

Thanks,
Ram
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17824749
Ah, yes, the environment. Do you have some details, O/S, Domino and Notes versions, etc?
0
 
LVL 3

Expert Comment

by:gdevianne
ID: 17825761
Ram,

code seems correct and should run ...

can the user the code is signed with acess that doc referenced with ndoc.NoteID

Also,
This workaround might help :
http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/090a4bd1e10c6aec85256d64002fd984?OpenDocument


0
 

Author Comment

by:rpdash
ID: 17835203
Hi gdevianne,

My problem is exactly the opposite. I cannot call an agent written purely in Lotus Scripts from COM. The solution given in the link is what exactly I cannot do right now.

sjef_bosman,

My environment is as follows:

Server:

Domino 6.5.2 hosted on Windows 2003

Client:

The client written in C# (.NET Framework 1.1) calling the COM object domobj.tlb of Lotus 6.5.2 client hosted on Windows XP Pro

Thanks,
Ram
0
 
LVL 18

Expert Comment

by:marilyng
ID: 18050557
Quick note: For COM applications, the Notes program directory must be in the application path to use runonserver.

I wonder if you create the newdocument with a specific "form" name, and then have a regularly scheduled lotus script agent act on those  documents and when done with the processing rename the form, then all your com agent has to do is create the document with the "form" name, and your runonserver agent can be modified to step through and process those "forms" at regular intervals.   If it doesn't find  collection, it just exits and writes to a log.

Also, the runonserver agent will write to the domino log: log.nsf on the server.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18256734
PAQed with no points refunded (of 500)

Computer101
EE Admin
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now