Link to home
Start Free TrialLog in
Avatar of TSO Fong
TSO FongFlag for Sweden

asked on

Agent: E-mail reminder for old documents

Greetings.

I'm trying to set up an agent that will run once a day, pulling a name field from each document on a given form with a particular status that was last modified more than five days ago, and sending that person a friendly reminder that they need to deal with the document.

The agent is set up on schedule to run on all documents in the database. It has the following formula:

AgeSecs := @Now - @Modified;
SELECT Form = "Request" & Status = "Submitted" & AgeSecs > 432000;

sendTo := Assigned;
copyTo := "";
blindCopyTo := "";
subject := "A Friendly Reminder";
remark := "Don't forget to deal with this!";
bodyFields = "";

@MailSend( sendTo ; copyTo ; blindCopyTo ; subject ; remark ; bodyFields; [IncludeDoclink])


But it doesn't seem to be working. To test it, I've got my own name assigned to the sendTo variable, with the agent set to run every half hour, and I'm not getting squat.

In the same database, I have a view with the following selection criteria:

Age := @Now - @Modified;
SELECT Status = "Submitted" & Form = "Request" & Age > 432000

This view shows eight documents, so I figure I should be getting eight e-mails every half hour, right?

But I'm getting nothing at all.

Any thoughts? Thanks -- b.r.t.
Avatar of Arunkumar
Arunkumar

Hi BarryTice,

To run scheduled agents you should have the agent signor to be included in the server document to "Run Scheduled Agents on this Server"

Make sure to include the server id also in this field.

Please check the restrictions in the server document.

Good Luck !

-Arun

Agent Signor - The id which saves the agent.

I think it's your selection formula.  I noticed the formula in your agent is different then your view.  Try putting the same formula in your view and see if any documents show up.
I feel the scheduling is not working . . .

ASKER CERTIFIED SOLUTION
Avatar of snocross
snocross

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
..also make sure it runs on ALL DOCUMENTS IN DATABASE and RUN HOURLY for the prior example.
Arun, you may be right, just trying to narrow down the possibilities.
Oh thats cool !

:)
Arun
Avatar of TSO Fong

ASKER

Arunkumar -- For my first effort at testing this, I made the mistake of having SELECT @All, and received ~8,600 e-mail notifications the first time the agent ran. (Oops!) So I'm reasonably confident that I can run agents. (Unless the network admin saw my first mistake and removed me from the list. But he's stuck in conferences all this week, so I doubt he's paying that much attention.)

After that first blunder (which took about 3 hours to finish...), I set up the above agent to run on the hour. With eight documents selected, I should have about 125 e-mail notifications waiting for me this morning, but I don't.

The agent is set to run on All Documents in Database, so I'm reasonably sure that isn't it. The e-mails I got from the first test were all marked as being "from" the server, not from me, as signor of the agent. That's correct, isn't it?

As far as the selection formula being different between the view and the agent, the order of the comparisons is different and the name of the variable is different, but other than that they seem identical to me.

Since the first effort worked, I'm guessing that the scheduler is working. I'll try snocross' suggestion of leaving SELECT @All and then conditionally sending mail, and see if that works.

Thanks for your suggestions so far. I hope this will work. -- b.r.t.
There you go !
Your schedule was working that sent tremondous amount of mails.
You have added a selection criteria now to the agent.

Now you have two possibilites.

Either your selection is wrong OR your admin person might have noticed & revoked the access to run scheduled agents.

Did you check the server document.  U will have access to read it.  Just check.

-Arun
PS: Snocross may be 100% right  :-)

OK, here's where we stand.

I'm in the server document for the server in the PAB on that server.
Under the Agent Manager section, Run Personal Agents is set to a group to which I don't belong.
Run restricted LotusScript/Java Agents has an asterisk.
Run unrestricted LotusScript/Java Agents is blank.

From my understanding, this means I should be able to create agents that will do what I need them to, right?

However, with snocross' suggestion, I modified the agent to SELECT @All and then to send the mail @If the form was correct, the status was correct, and the document was sufficiently old. It's set to run every half hour. It's been 30 minutes since I changed the agent, and that has included passing the top of the hour (9 a.m. locally).

The view I created now shows 20 documents that are more than 5 days old. But still, I've received no e-mails.

Any more ideas?
Try this in an Agent that runs on all documents in the database:


     Dim S As New NotesSession
     Dim Db As NotesDatabase
     Dim CollModDocs As NotesDocumentCollection
     Dim Doc As NotesDocument
     Dim DocMail As NotesDocument
     Dim RTBody As NotesRichTextItem
     Dim SearchFormula As String
     
     Set Db = S.CurrentDatabase
     
     SearchFormula = {(Form = "Request") & (Status = "Submitted") & ((@Now - @Modified) > 432000)}
     
     Set CollModDocs = Db.Search ( SearchFormula, Nothing, 0 )
     
     Set Doc = CollModDocs.GetFirstDocument
     
     While Not Doc Is Nothing
          Set DocMail = Db.CreateDocument
          With DocMail
               .Form = "Memo"
               .SendTo = Doc.Assigned (0)
               .Subject = "A Friendly Reminder"
               Set RTBody = DocMail.CreateRichTextItem ( "Body" )
               Call RTBody.AppendText ( "Don't forget to deal with this!" )
               Call RTBody.AddTab ( 2 )
               Call RTBody.AppendDocLink ( Doc, "Click to open document." )
          End With
          Call DocMail.Send ( False )
          Set Doc = CollModDocs.GetNextDocument ( Doc )
     Wend

gogglehead
I could send you lotusscript too but I figured you want to get the @formula working... you should try using no selection formula at all and hardcoding your name just to see if it works.  Either there's a problem with the selection criteria or a problem finding your name, if it works with no criteria then it is your selection formula.  If it doesn't work then there's a problem finding your name.

(If you're going to use Lotusscript then I can give you code that will run on the view that you already have.  Then the script will just process what is in that view)
gogglehead --

Thanks!

I'm still new at LotusScript, so I'm not real up on the specifics of the grammar and vocabulary. What is the format I should use for my name in the DocMail.SendTo to have one round of these sent to me as a test before I release it to the world at large?

-- b.r.t.
No worries :)

Use the format CN/O (e.g. "Big Bob/Lotus").

This LotuScript should be easy to get to grips with, it works in just the same way as the formula but instead of a select it uses a Db.Search (just the same really but it gives you back a document collection).

snocross - I would have used the view too but that means the view is building all the time and if you have a view with a time based selection formula like that then it causes performance problems because it has to rebuild every time th indexer hits it ;) I thought that the view was just there as a test, I hope it's not there all the time.

I already had the Agent, just thought you could use it.

cheers me dears,

gogglehead
snocross -- The view I have is a temporary, private view I created to test my selection criteria, though I could create a hidden view in the database that would do that.

I'm not married to my @Formula, and am happy to accept any answer I can get. But I would like to know why my @Formula isn't working.

As I mentioned above, I first tried it with no selection criteria and hard-coded to mail to me. I got ~8,600 e-mails.

When I added the selection criteria, I get nothing (though it is still hard-coded to me in my tests).

(The code above has been modified to demonstrate my eventual intent; the code in my test has my name hard-coded.)

Because I got 8,600 e-mails, I'm confident that it's finding me. But because the selection criteria for the agent is identical to the selection criteria in the view (I've changed the view criteria to exactly match), I can't understand why the agent isn't now sending me e-mails for the 20 documents that show up in the view.

I don't have administration access to the server. (And it's been three years of not doing any Notes administration since I took Admin I.) Is there any easy way I can tell if the agent scheduler is running properly and handling all the agents it should?

Thanks! -- b.r.t.
Put a print statement in the agent then it will show up in the server log when it runs.

ie:

Print "Agent Started"
....code
Print "Agent Ended"
Erf.

I tried your code, gogglehead, and when I went to save the agent, I got a window with the following:

You do not have execution access privileges for this agent on '{server name here}'; agent will not run.

Any ideas?
Ah, I failed to check the "Shared Agent" flag. Let me try again.
Unfortunately, tracking that down put me past the top of the hour. Now it will be another 25 minutes before I know if it worked! :(

Thanks for your help, guys. You'll both be getting points for this.

snocross -- That goes in the LotusScript code, after the Sub Initialize and before the End Sub, right?
Remember you can run the Agent on your machine to test it and have the debugger on. Then check the count in the collection to make sure that it's not going to send you loads of mails again.

Run the Agent locally by highlighting it and right clicking and selecting Run. Make sure the debugger is on first ;)

If there are too many documents in the collection then you can always press stop!

Another useful statement in the Script is to include a Stop statement for the debugger, whenever it encounters this it will pause and wait for you to press continue or stop ;)
Right.. you can put the print statements pretty much anywhere and say whatever you want.  It's a crude way to debug but it works.
Actually, I just tried to run the agent by taking it off the hourly schedule and running it from the menu.

The log showed the following:

Started running agent 'SendMeMoreMail' on 07/14/2000 10:08:14 a.m.
Running on all documents in database: 8364 total
Found 8364 document(s) that match search criteria
Ran LotusScript code
Done running agent 'SendMeMoreMail' on 07/14/2000 10:08:28 a.m.


There was also a pop-up saying that it couldn't find the default view of the database. (?)

---

I've returned the agent to it's half-hourly schedule, and just ran it from a right-click. It gave the same log info as above (with updated times, of course), and I still received no mail.

The line in the LotusScript that sends the mail is:

    SendTo = "Barry R Tice/ABC/DEF@DEF"

Is this correct?
How do you turn the debugger on?
Go to File->Tools->Debug LotuScript
Go to File->Tools->Debug LotuScript
That's the agent log, the print statements will show up in the server log database.

To turn the debugger on/off:
FILE/TOOLS/DEBUG LOTUSSCRIPT
File - Tools - Debug LotusScript
Oops !!!

Look at the timings on the comments !

:-)
Arun
That's the agent log, the print statements will show up in the server log database.

To turn the debugger on/off:
FILE/TOOLS/DEBUG LOTUSSCRIPT
Haha, that's another fine mess you've got me into :)

I love it when a plan comes together.
When I step through this, it gives me 14 documents in the COLLMODDOCS document collection. (That's good.)

And I realized that there was no default view for the database, so I selected a view that would show the records in question and assigned it as the default, and that took care of the default view error.

And I just received all e-mails. That's good, too.

Now all I need to do is let it run through a cycle and see that it works on schedule.

Patience for this kind of waiting was never my strong suit...
Woo hoo!

Apparently our servers are set to run things at 8 minutes before the hour.

I just got 14 e-mail notifications.

The funny thing is, my test view is showing 6 documents.

The selection criteria for the view is:
AgeSecs := @Now - @Modified;
SELECT Form = "New Change Request" & Status = "Programming" & AgeSecs > 432000

and the selection criteria for the agent is
SearchFormula = {(Form = "New Change Request") & (Status = "Programming") & ((@Now - @Modified) > 432000)} :

Why would the Script version of this find more documents? From the checks I've made, all 14 of the documents do fit the criteria -- they're more than 5 days old. Why, then, aren't they found in the other view?
Also, the mails I'm getting are now from me instead of being from the server. Can this be changed?
Well probably the clock on the server is slightly off from yours... thus the two extra docs.
Hi Barry !

Try and save the agent with the server id.
Hope this should send the mail from the server id.

-Arun
The mails will come from whoever signs the Agent to run on the server (the person that enables the Scheduled Agent). I don't know if you can modify the From and ReplyTo fields in the mail because they might be overwritten when sending the mail but you could try it.

To see why more documents are found by the Agent use the exact select formula in the Agent for the view (including brackets). The other difference could be that the Agent finds response documents and the view doesn't (it will only display resopnse documents if ther is a column for them and if the parent is in the view), if you are using responses at all.

I'm glad you have something working now ;)

gogglehead
-snocross
-Arunkumar
-BarryTice

Thanks for the laughs and a marathon question
When I experimented yesterday using @Formula (as this thread began) and I accidentally sent myself ~8,600 e-mails, they all said they came from the server. Why didn't they say they came from me then?

There are no response documents in the database. Everything is on first-generation forms.

I've tried setting the selection criteria on my view to:
SELECT (Form = "New Change Request") & (Status = "Programming") & ((@Now - @Modified) > 432000)

This matches the criteria of the agent, but I still only get 6 documents, compared with 14 from the agent. Just one of those things, I guess.
It gets weirder.

I disabled the agent and enabled the @Formula one again, to see what would happen. The @Formula one is now working. Furthermore, it is sending mail "from" the server rather than me.

Any ideas on why this would be?
Weirder yet.

The @Formula version of the agent is also sending 14 documents, in spite of the view with the same selection criteria only showing 6.

Oh dear
How about reader names fields, roles?
Nope. No roles, no readers fields. Good thinking, though.

I'm doing the unthinkable, too. I've set the schedule to run on this thing at 1 a.m. (no weekends), so it should run Monday morning, sending e-mails to the people on the list with records that fit the criteria. But I'll be on vacation until Wednesday, so if it blows up royally, I won't be in a position to fix it.

Perhaps it has something to do with replication conflict documents?

I'm logging out until Wednesday. If anyone comes up with anything, please post it.

I'll be awarding points for all your contributions then. (Really, I'm not ignoring you all!)

-- b.r.t.
It could be replication/save conflicts because they are made as responses to the original. You could check it by using the debugger and cycling though each document and checking it in the document Items list (all the fields). There should be a $Conflict field in any conflict document. You might also chck some other things out about the documents and see if you can find out where they are ;)

gogglehead

P.S. Don't worry about the points, we all do this for fun.
Comment accepted as answer
Thanks for the help, snocross. I never did figure out why the thing was being so flakey, but it seems to be working now. @SELECTing @All and then sending mail conditionally seemed to do the trick.
Thanks, I'm glad it's finally working!