.. done Morning Batch ============= 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 Involvement. We will add new functionality as new use cases arise. Set Up the Morning Batch ------------------------ You must have an IronPython script called `MorningBatch` in `Admin > Advanced > 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 `Admin > Advanced > Settings` and change the setting `MorningBatch` to `True`. This setting is found on the General tab. .. note:: If the Python scripts in your Morning Batch require special roles (such as, for example, the `Finance` role), you can use 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 `Admin > Advanced > Special Content > Html Content` 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. .. important:: 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. .. note:: 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: ``https://**yourchurch**.tpsdb.com/Batch/RunScript/**Scriptname**`` 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. Sample Search ------------- 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. .. figure:: https://i.tpsdb.com/2015-07-08_12-58-51.png :target: # Sample Search for: FaithPath Purity 14 Yr Olds Sample Morning Batch Python Script ---------------------------------- Copy the following script, paste it into your new text file:: model.EmailContent("FaithPath Purity-14yrs", 819918, "pastor@testchurch.org", "Pastor Smith", "Faith Path Purity", "Purity-14yrsmail") Note the following in the above script: ``"FaithPath Purity-14yrs"`` This is the name of the saved search ``819918`` This is the People Id of the person who will queue the email (the person sending on behalf of the minister). ``"pastor@testchurch.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. ``"Purity-14yrsmail"`` This is the name of the HTML special content for the email. .. note:: 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, "pastor@testchurch.org", "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) | | +--------------------+------------------+ | **Latest Update** | **3/4/2024** | +--------------------+------------------+ Update for new menu