You can have a Python script run every morning around 4:30 Central Time. It can do things such as send an email to the results of a saved query or send email reminders to members of an organization. We will add new functionality as new use cases arise.
Set Up the Morning Batch¶
You must have an IronPython script called MorningBatch in Administration > Setup > Special Content > Python Scripts.
At the bottom of this document is a sample script. Copy it and paste it into your new text file (in order to get the indentations correct). Then revise it as needed, making note of the explanations for each part of the script.
You must also go to Administration > Setup > Settings and change the setting RunMorningBatch to True. This setting is found on the System tab in the Administration section.
If the Python scripts in your Morning Batch require special roles (such as, for example, the Finance role), you can add the setting MorningBatchUsername and enter as its value the name of a user account that has the required roles.
If you want to send an email, you will need to do the following:
- Create an email
- Add this in Administration > Setup > Special Content > Html Files with the appropriate message, graphics and replacement codes.
- Name the file appropriately.
- This name will be referred to in the Python script.
- Create and save a Search in Search Builder to select your recipients.
For example, you could find all children whose fourteenth birthday is today. Below is a sample search.
The username of the owner of the search must be public. (That user does not have to exist in the database.)
- Decide who the email should come from.
- This will probably be a minister.
- Decide who the email should be queued by.
- They will send the email on behalf of the From person.
The From person and the ‘queued by’ person could be the same. The reason you might want two different people is so that a minister as well as an administrative assistant can view the sent emails.
Testing Your Script¶
Navigate to the following URL:
Be sure to substitute the name of your church (as it is in your TouchPoint URL) and substitute the name of your script in place of Scriptname.
This will run the script and send the emails. If you want to just test your settings, create a search that will return only you (or a few staff members), and use that search in your script for testing purposes. Do this before you set up your other searches.
This is a sample search which will return parents whose children turn 14 years old today and one of the primary adults is a member of the church.
Sample Morning Batch Python Script¶
Copy the following script, paste it into your new text file:
model.EmailContent("FaithPath Purity-14yrs", 819918, "email@example.com", "Pastor Smith", "Faith Path Purity", "Purity-14yrsmail")
Note the following in the above script:
- This is the name of the saved search
- This is the People Id of the person who will queue the email (the person sending on behalf of the minister).
"firstname.lastname@example.org" and "Pastor Smith"
- That is the email address and name of the Sender of the email (the minister).
"Faith Path Purity"
- This is the subject of the email.
- This is the name of the HTML special content for the email.
To send multiple emails, create both an email and a search for each different email you want to send. Copy the part of the script from model.EmailContent through the end and paste it beneath the existing script. Make the necessary revisions.
Performing an Action on a Particular Day of the Week¶
If you only want to perform an action on a particular day of the week, then you must use a conditional IF statement and test the DayOfWeek parameter.
For example, if you only wanted an email to go out on Thursday, then you can see in the revised sample script below that we can accomplish this by adding a single line of code:
if model.DayOfWeek == 4: model.EmailContent("FaithPath Purity-14yrs", 819918, "email@example.com", "Pastor Smith", "Faith Path Purity", "Purity-14yrsmail")
Note the following details about using the DayOfWeek condition:
- DayOfWeek returns an integer representation of the day of the Week. Monday = 1, Tuesday = 2, etc.
- The actions that will be performed when the condition is true must be indented following typical Python practice
- Multiple actions can be performed under the same conditional test (e.g. send two emails)
Modify image link with secure protocol.