I call an agent to run on server in my queryclose

I have an agent that updates lots of documents on the save and close of a setup document.

I called the agent as runonserver thinking that this would help the user not experiencing having to wait till all the docs were processed before the document they were modifying would close.

But, after I call the agent, I’m still stuck waiting for it to finish before control is given back me.

I searched in this forum… and found a recent posting…

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/0adf57f45d640f218525737c00607927?OpenDocument

The resolution mentioned didn’t work for me…

I’m really needing some help on this one… The agent has to process sometimes 1000s of documents… and I don’t want the user to have to wait several minutes before they can continue on.

Thanks in advance for any help…

Subject: Here’s how to do what you want to do.

My solution, which you referenced, is for situations where the client is still waiting for the RunOnServer to complete even thought it’s already finished. As you already realized, implementing it does nothing but give you what you already have (albeit more reliably.)

In any case, the answer you’re looking for is called NotesSession.SendConsoleCommand. What you’re going to do is send a console command to execute the update agent. You do this from an agent that I usually refer to as a kicker agent (kicks off the process.) You must use the kicker because the agent that executes the SendConsoleCommand must have administrative rights to the server.

Create an agent that calls this method to start your update agent. Call it UpdateKicker. It will contain two lines of code:

Dim Nsess as New NotesSession

Nsess.SendConsoleCommand( |tell amgr run “apps/mydb.nsf” ‘UpdateAgent’| ) '(<-edited 11/10/07 to remove double quote before tell.)

On the Security tab for this agent, enter a name into the "Run on behalf of " field. Make sure this user has administrative access to the server. Also, make sure the SIGNER of the agent is listed in the server’s “Sign agents to run on behalf of someone else:” field under the security tab of the server configuration document. Okay you’re done.

In your PostSave execute the UpdateKicker

(note: I’m writing on the fly so commands may not be exact. consider it pseudo code.)

Dim Nsess as New NotesSession

Dim KickerAgent as NotesAgent

Set ThisDB = NotesSession.CurrentDatabase

Set KickerAgent = ThisDB.GetAgent( “UpdateKicker” )

Call KickerAgent.Run 'Note: Don’t need RunOnServer here

Here’s how it works.

You get a handle to the kicker agent and execute it.

Even though you are executing the agent, it runs with the rights of the user listed in the “Run on behalf of”

The agent sends the console command and ends. Control returns to the client.

Meanwhile, the agent that was kicked off by the console command is now running.

You didn’t say whether your agent is executed by a single person, or may be executed by several people at the same time. If the agent might be executed by several people at the same time, then you have to design your update process to be aware of that. You may want to review the Designer help documents on running agents asynchonously.

Good Luck!

Subject: RE: Here’s how to do what you want to do.

Thanks so much for your detailed answer.

I will give it a whirl…

By they way, you aren’t the “Great Wilfredo” are you? Who came up w/the @sum function in version 3 of Lotus Notes…

Subject: RE: Here’s how to do what you want to do.

Why…yes I am! Nice of you to remember! Thanks! :o)

Subject: RE: Here’s how to do what you want to do.

Wow! A real legend… I haven’t seen your name out there for a long time…

I of course am a Notes Groupie… And would love to meet you in person. I have always thought you were brilliant… But, thought perhaps you had changed careers.

Glad to see you again. And thanks again…

Hope to see you at a lotusphere one day…

Subject: RE: Here’s how to do what you want to do.

Thank you for your kind words…I appreciate it! :o)

However, I doubt you want to meet me…I became disenchanted with Notes when R4 came out and Iris didn’t seem to have addressed any of the issue that were causing all programmers grief. Ever since then I’ve disliked Notes. That’s pretty much why I dropped out of sight…just stopped being “into it” and haven’t been for a long time.

I would love to move to some other technology but the opportunity hasn’t come up yet. I’m actually looking for work now and I’m hoping to land a migration project with a place that’s moving to SharePoint or something else like that.

I visit this forum very infrequently. Every once in a while I run into a problem that I don’t feel like solving, so I come to see if someone else has…though usually all I find is others with the same problem so I end up solving it anyways! :stuck_out_tongue:

But then I hang around for a short time and answer a few questions, hoping that I’ve lent a hand to a deserving soul…and it looks like I did! :slight_smile: So, glad I could help out! Take care!

Subject: Well… I still think you are Brilliant!

Sorry you have become disenchanted w/Lotus-Domino. Back in the day, I remember you posting all kinds of wonderfull things in the Partner’s forum. Back when the partner’s forum was a place where that kind of information was posted.

From your other postings, your experience runs so much deeper than mine. I’m so ignorant, that I don’t even know the problems you have experienced. My code must be so simple, that I never have many problems.

Recently, I have run into some limitations, like the 64k limitation and the 30k @UserNames limitation that have caused me some grief…

I have been a notes developer since Release 2…and I hope to retire in 5 more years. Hopefully, Notes/Domino will be remain strong for at least 5 more years…

Take care yourself… Keep the faith… you know Domino developers are cult members! And go to Lotusphere so I can get your autograph!

Subject: RE: Well… I still think you are Brilliant!

Subject: I call an agent to run on server in my queryclose…

Hi Betsy,

I’m not sure you’ll be able to get round this problem as you’re triggering your agent using LS on the close of a document. I think this means that you are creating a NotesAgent object and that object exists until it finishes running, which means your LS can’t finish until the agent has finished. (I think this is correct, anyway).

You could try setting your agent to ‘Run in background client thread’ but this won’t work if you trigger it using LS (see: http://www-10.lotus.com/ldd/nd6forum.nsf/7524faba161e725085257050006f194c?OpenForm&ParentUNID=EED5E6F4CB0A5F2B8525738E0041023D ). However, you can change the OnUnload event of your form to run Formula though, and get it to use ToolsRunMacro or RunAgent instead.

Hope this helps.

Emily.

Subject: I call an agent to run on server in my queryclose…

Thanks for everyone’s ideas. All the ideas seem great! I thank you for your help.

Subject: I call an agent to run on server in my queryclose…

If you can live with the fact that some updates will be done later, than you might consider to have a scheduled agent (ran on the server) that processes all the modified documents by checking some value you set in the queryclose event.

Don’t forget to reset this indication once you have processed the document.

Subject: I call an agent to run on server in my queryclose…

one idea would be to send an email to your db and use “before email arrives” agent. This will trigger the updates nearly simultaneously and will free the client to close at once.

Subject: RE: I call an agent to run on server in my queryclose…

It is generally not a good idea to let the router (which is actually executing the “Run Before Mail Arrives” agents) deal with these kinds of updates, as they are blocking a delivery thread (I’m not sure whether this means blocking all mail delivery).

If updates should occurr in the background, the agent manager is the best place to deal with this.

cheers,

Bram