How to run an agent in another database

Hi, I’m using a Java Agent for this.How do I run agents that perform work on one database from another database? Here is the exact situation…

Audits.nsf on LOCAL - Agents: CopyAndDelete and CreateStarterDoc

Questions.nsf on LOCAL - Agent: DeleteAllDocs

Audits.nsf on SERVER - Agent: RemoveStarterDocs

Questions.nsf on SERVER - Agent : CopyDocsToLocal

I want to run all of these agents from one button in Audits.nsf on LOCAL at the same time that I’m running CopyAndDelete and CreateStarterDoc. I can’t schedule the job, because LOCAL is on a tablet PC that will not be connected to the network. When the user returns it to the docking station, they will press the button and run all these agents.

Does anybody know how I do this?

Subject: RE: How to run an agent in another database

Read about Agent.run and runOnServer. Also, please note that just because an agent is stored in one database, doesn’t mean it can’t access data in other databases; there might not be any need to run the other agents on the server if the user has access to do whatever changes it is you need to do on the server.

However, you might want to say more about your application, because the names you have chosen for your agents are very scary. It sounds like maybe you are deleting a lot of documents from your local replica – is it a replica? Or a database with a different replica ID that just happens to have the same name? – and then you re-create them from the server. This is very inefficient in terms of view indexing, replication, database size, …

It sounds like maybe what you have is different databases with the same filenames, which you are trying to synchronize in a very wrong way, whereas perhaps what you really need are local selective replicas.

  • Andre Guirard, IBM/Lotus Development

Useful blog: Best Practice Makes Perfect

For faster answers, be C R I S P Y

Subject: RE: How to run an agent in another database

Hmmmmm…you have me very worried now, because I’m doing this, and I really don’t know anything about Lotus Notes. I just got drafted!

There is a local database called Audits, and a local database called questions. These reside on a Panasonic Toughbook. All day long, the auditor will perform audits on this tablet. What actually happens during this process, is that an agent is run from the Audits database on local, and it gets all sort of information from the Questions database, like employee names, audit questions, names of machines, etc.

At different points during the day, the auditor puts the tablet into the docking station, which connects the tablet to the company network.

What happens now, is that he hits a button, and all the audits that he did today are copied into a different database, also named Audits, on the server. Its pretty much the same architecture, except its only used for viewing, editing and approving edits, not for conducting them. After the audit documents are copied from the tablet to the network database, they are deleted from the tablet (this does not happen if the copy function fails), and then a sample audit document is created for the local Audits database on the tablet.

What I want to happen at the same time is for the local Questions database to be replaced by the network Questions database. The Questions database on the network has a lot of additional Java GUI agents for creating and editing the documents. These features are not on the tablet’s local Questions database, because we do not want the auditor to be able to change this core data. I need the documents from the network Questions to be copied to the local Questions so that if a manager makes a change, it will be reflected during the next auditing session.

I hope that this makes sense. Unfortunately, I’m at a point time wise where I can’t make too many changes. I just need to have this work. I looked into the runOnServer, and I know it sounds dumb, but I can’t figure out how to make it work. It just gives me a null pointer exception every time. Almost like it doesn’t see the server or something.

Thanks again for your help!

Subject: RE: How to run an agent in another database

The usual way to make sure someone has an up-to-date local copy of all the data in a server database, as with the Questions database, is to give them a local replica. This is very easy, requires no coding, and if you want to restrict editing the data to certain persons, you just need to limit their access using the application’s access dialog (file / database / access control). When they connect in after a spell of being disconnected, the database will replicate its updates along with their other local databases, such as their mail file. If you want to make extra sure, the button your person presses can use the NotesDatabase.Replicate method (or Database.replicate if you’re using Java) to force an update. But you don’t have to write the sync code yourself, and replication of just the changed documents is much faster than copying it all every time!

As for the other database, it sounds like the approach you are using is architecturally sound, but I don’t understand why you think you need multiple agents. You want to find all the documents in one database (two lines of code, not counting declarations – add one if you don’t want all the documents), copy them all to another database (four lines), delete them all (two line), and create one sample document (complexity depending on what data you want in it, but probably not more than 20 lines), and you want multiple agents for this? In multiple databases? All this can be in one agent in the local database.

As far as your null pointer exception, this is not caused by an error in the method you’re calling, but by an error in your code. As you haven’t shown any of your code, it’s impossible to say what the problem is. But look at the Java call stack, find the line where the error occurred, and think about what pointer is being used on that line and what its value might be.