We help IT Professionals succeed at work.

Running Lotes Notes agent from .NET

rpdash
rpdash asked
on
Medium Priority
1,380 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
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:

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

 
I hope this helps !
CERTIFIED EXPERT
Top Expert 2007

Commented:
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 !

Author

Commented:
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

Author

Commented:
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
CERTIFIED EXPERT
Top Expert 2007

Commented:
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 !

Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
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?

Author

Commented:
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
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
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?

Author

Commented:
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
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
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?

Author

Commented:
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).
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
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... ;-)

Author

Commented:
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
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Ah, yes, the environment. Do you have some details, O/S, Domino and Notes versions, etc?
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


Author

Commented:
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

Commented:
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.
PAQed with no points refunded (of 500)

Computer101
EE Admin

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.