I have an intern form with a graduation date field. Now I want to send an email to a certain group of people 6 weeks before the graduation date. So I’m going to write this scheduled agent running every night. Can somebody help me in writing the code for checking for those 6 weeks. For example there is person A graduating on Jan 25 which is 6 weeks from now and Person B graduating on Feb 15. In this case I would like to send an email to the application administrators that Person A will be graduating 6 weeks from now so please start preparing his graduation package.
Have a look at the topics under “Date and time handling” in the Index of the Designer Help. You mmost likely want to use @Adjust to move Today on by the 42 days, then see if the graduation date is less than or equal to this.
Here is a sample code (in Java). This Java agent has to run on schedule daily. It also needs a view in your database with first sorted column as the Date field of interest. (I have written this for you, but didn’t notice you need a Lotus Script agent. Let that be brain teaser for you.)
import lotus.domino.*;
/**
* @Author Byju Joy
**/
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
Database db = agentContext.getCurrentDatabase();
View vw = db.getView("InProcess");
//creates a date object representing date after 6 weeks from today. Used as key in view lookup.
DateTime keyDate = session.createDateTime("Today");
keyDate.adjustDay(7*6);
System.out.println("keyDate = " + keyDate);
DocumentCollection dc = vw.getAllDocumentsByKey(keyDate, true);
Document doc = dc.getFirstDocument();
while(doc != null){
//Process the doc
System.out.println("Processing doc " + doc.getItemValue("Date") );
doc = dc.getNextDocument(doc);
}
} catch(Exception e) {
e.printStackTrace();
}
}
You can create a hidden computed field on the form called something reminderDate. It would compute to the date the email needs to be sent using @Adjust in formula language. Then, your scheduled agent can see if reminderDate = @Today to send the email or else it skips it. Another thing you could do although not recommended is to have a view that includes only documents with reminderDate = @Today. Then run the agent against all docs in the view.
Damian’s suggestion is a good option. I would recommend it.
If you really want to do it in LotusScript, this example should be helpful.
In this code, a notesdatetime value called rightnow is calculated 30 days prior to Now. Later in the code while looping through the documents, the creation date of the document is compared to the calculated notesdatetime value and an action is taken. You would use six weeks and would compare to the form date field you select instead of the creation date.
'declare and set a comparative value equal to now
Dim rightnow As notesdatetime
Set rightnow = New notesdatetime (Now)
' set the comparative value back ten days
Call rightnow.adjustday(-30) ' set to 30 days ago
'LATER IN CODE, when looping through documents.
If (doc.created < rightnow.LSLocalTime) Then
'do your action here
' probably need to update a field showing that the
' email was sent and check for this field in your
' selection so that you don't keep sending information about this document.
end if