Hello all,
I have a form that does the following. The user fills in fields that have a variety of information regarding their client. One of those fields is a “Meeting Date” field which indicates when they are schedule to or have already met with the client. Once this date has passed, I would like to trigger an email routine that I already have in the forms postsave event that sends a reminder email to the person stating “You had your meeting with Client XYZ on Meeting date. Please followup on items X, Y and Z”. My postsave code is as follows:
REM {Send email to Manager when meeting date has passed};
@If(DTC_15 != NULL & YN_15 != “” & Meetg != NULL & SPFlag = “” & @Today > Meetg;
@MailSend(Manager; “”; “”; "Planning Considerations for " + CName; "From the planning meeting on " + @Text(Meetg) + " it was discussed to review Succession Planning on or about " + @Text(DTC_15) + “. This serves as a reminder that you should start to look at addressing this meeting. Please schedule a meeting with all parties involved to review.” + @NewLine + @NewLine; “”; [IncludeDoclink]);
“”)
My @ formula is basically saying that if the key fields are popoulated AND today’s date is greater than the meeting date then send the email. What is the best way to update this document daily so that it is resaved and retested for the postsave criteria? Would a simple agent that includes @Command([ToolsRefreshAllDocs]) actually trigger the postsave event for all documents in the database as I’m hoping and then force the email to go out when the meeting date has arrived as I’m hoping?
Thanks in advance
Subject: Updating/recalculating documents via agent
PostSave is the wrong way to do this, as that method is only called when an open document is saved in the client.
Instead, you would be better off with a nightly scheduled agent that selects any meetings in the past and send an e-mail. That agent would then set a field / flag in your document so it’s ignored by that agent in the future.
Subject: RE: Updating/recalculating documents via agent
Thanks for the advice and guidance Graham. I will change my logic and go in the direction that you suggested. However, for my own knowledge, if I left it as is (postsave) and created an agent that looped through the docs by updating a field within each document then saving the docs in the backend, would this accomplish the same thing? For instance, if I had a scheduled nightly agent that updated a text field as a basis:
Dim s As New notessession
Dim doc As notesdocument
Dim dc As NotesDocumentCollection
Dim db As notesdatabase
Set db=s.currentDatabase
Set dc=db.AllDocuments
Set doc = dc.getfirstdocument
Do While Not ( doc Is Nothing )
doc.CName = doc.CName
Call doc.save ( True, False )
Set doc = dc.getnextdocument ( doc )
Loop
Would this trigger the postsave event? Also, whom would the email be addressed FROM? As mentioned, this is for my own knowledge/learning experience. I will indeed take your advice.
Subject: RE: Updating/recalculating documents via agent
Nope - Agents updating NotesDocument objects won’t trigger any document events. The events are associated with the forms, not the documents.
If your agent opened a UINotesDocument, and did a UIDocument Save, that would trigger the event, but the user would see the open document on their screen, and this should only be done if you are updating a very small number of documents. (I would not recommend doing this…)
If your agent is sending mail, it will be from the ID that’s running the agent. If you run it, it will come from you. If it’s scheduled, it will come form the Server’s ID.
Subject: Scheduled agent runs but no emails are sent
I’m still not quite there. The scheduled agent runs as expected and flags the flag field as “mailed” but the email never gets sent. I’m running the agent on a server replica and have it set to run on server. Nothing is set under “run on behalf of”. The server in question is set in the config doc to run agents…I’m at a loss at this point. ANy insight as to why the emails are not being sent even though the agent runs on schedule as expected?
PS
The code seems to be fine because it runs as expected if triggered manually. I get the emails going out and the flag field is set. When scheduled, the emails don’t go out but the agent does run.
Subject: FINALLY!
After much research and investigation, it turns out that all of my code was fine, the agent was set correctly and all parameters in my server document regarding security levels were fine.
To use @MailSend with the [IncludeDocLink] parameter, the database in question must contain a default view. My database did not have one defined! Once I defined a default view, the email triggered on scheduled an was addressed FROM the server.
Thanks again for all your help and time Graham!
Subject: RE: Updating/recalculating documents via agent
Thanks for all of your help and insight Graham. I have a much clearer picture of what I need to do now.
Subject: ERRANT POST - Please disregard