rpdash
asked on
Running Lotes Notes agent from .NET
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(doc umentId). Please refer to the code below:
01 NotesSession ns = new NotesSessionClass();
02 ns.Initialize(currentPassw ord);
03 NotesDbDirectory dbDir = ns.GetDbDirectory(ServerNa me);
04 NotesDatabase notesDatabase = dbDir.OpenDatabase(Databas eName, false);
05 NotesDocument ndoc = notesDatabase.CreateDocume nt();
06 ndoc.ReplaceItemValue("For m", FormName);
07 ndoc.ReplaceItemValue("Ema ilAddress" , "abc@xyz.com");
08 ndoc.Save(true, false, false);
09 NotesAgent agent = notesDatabase.GetAgent(Age ntName);
10 agent.RunOnServer(ndoc.Not eID);
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
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(doc
01 NotesSession ns = new NotesSessionClass();
02 ns.Initialize(currentPassw
03 NotesDbDirectory dbDir = ns.GetDbDirectory(ServerNa
04 NotesDatabase notesDatabase = dbDir.OpenDatabase(Databas
05 NotesDocument ndoc = notesDatabase.CreateDocume
06 ndoc.ReplaceItemValue("For
07 ndoc.ReplaceItemValue("Ema
08 ndoc.Save(true, false, false);
09 NotesAgent agent = notesDatabase.GetAgent(Age
10 agent.RunOnServer(ndoc.Not
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
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.Not eID(0));
Since most fields allow multiple values in an array.
I hope this helps !
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.Not
Since most fields allow multiple values in an array.
I hope this helps !
ASKER
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(Databas eName, false);
05 NotesDocument ndoc = ndb.CreateDocument();
06 ndoc.ReplaceItemValue("For m", FormName);
07 ndoc.ReplaceItemValue("Ema ilAddress" , "abc@xyz.com");
08 ndoc.Save(true, false, false);
09 NotesAgent agent = ndb.GetAgent(AgentName);
10 agent.RunOnServer(ndoc.Not eID);
and it would not have made any difference.
Thanks,
Ram
04 NotesDatabase ndb = dbDir.OpenDatabase(Databas
05 NotesDocument ndoc = ndb.CreateDocument();
06 ndoc.ReplaceItemValue("For
07 ndoc.ReplaceItemValue("Ema
08 ndoc.Save(true, false, false);
09 NotesAgent agent = ndb.GetAgent(AgentName);
10 agent.RunOnServer(ndoc.Not
and it would not have made any difference.
Thanks,
Ram
ASKER
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
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
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 !
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 !
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?
ASKER
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
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
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(Age ntName);
10 String noteID= ndoc.NoteID;
11 agent.RunOnServer(noteID);
Which line makes it stop now?
Other option:
09 NotesAgent agent = notesDatabase.GetAgent(Age
10 String noteID= ndoc.NoteID;
11 agent.RunOnServer(noteID);
Which line makes it stop now?
ASKER
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
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
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?
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?
ASKER
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).
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... ;-)
I think I'll use the night (it's 01:22 over here) for some reflection... ;-)
ASKER
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
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
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
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
ASKER
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
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
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
04 NotesDatabase notesDatabase = dbDir.OpenDatabase(Databas
why twice NotesDatabase . I think only 1 is needed
I hope this helps !