BridgeQueryTags Python Script

View the Code

Suggestion: Right click the link and use open link in new window then arrange your windows you can view side by side.

Build your Categories

In the BridgePlus recipe we use 7 different categories of current or potential donors. All of the recipients targeted will be Primary Adults.

Each Category is described below along with its name which is also the name of an internal tag in the database. Earlier Categories in the list take precedence over the latter Categories.

BridgeNewMemberWeek3
Recently joined the church 3 weeks ago but have not given to the fund. And they have not already received this email.
BridgeNewMemberWeek5
Recently joined the church 5 weeks ago but have not given to the fund. And they have not already received this email.
BridgeNewMemberWeek7
Recently joined the church 7 weeks ago but have not given to the fund. And they have not already received this email.
BridgeNonGivers
Active Attender (you define) who has not given to the fund in the past 365 days.
BridgeLapsed90Days
Active Attender who has not given to the fund in the past 90 days.
BridgeLapsed120Days
Active Attender who has not given to the fund in the past 120 days and has already received the BridgeLapsed90Days email and has not already received this email.
BridgeRecentDonors
Anybody who has given to the fund since the last campaign email was sent.

Code Review

This script creates a special type of tag called a QueryTag. This is not a normal Tag that a user creates in Touchpoint, but at bottom, it uses the same Tags table in the database. These tags can only be created with a Python script.

The name of the Tag is the name of the Category.

While reading the descriptions that follow, you should be viewing the code side-by-side. See BridgeQueryTags Python Script.

Line 1 is where you set whether you are debugging this script or not. You can set this value to True or False.

Line 2 sets the AddFilter to None by default. AddFilter is a way for you to test with a sample group of people who won’t mind getting test emails. Typically this would be staff, or fake people that will exercise each category with sample Contribution records. On Line 5, we set this to filter by those who have an Extra Value Checkbox (boolean value) called BP-TestGroup which is set to checked (1 = true)

Line 6 resets the BridgeSinceDate setting so that you can run multiple tests with the same data.

Line 8 Deletes old QueryTags whose name starts with Bridge. This allows each run to use fresh data.

Lines 12-18 define a function called Tag that will be used to create each QueryTag. The function takes two parameters, the name of the tag and the code that defines who should be included in the tag. It also, creates a report to display the results making it easy to see how your QueryTags script is working.

The remainder of the script calls this function seven different times, once for each Category.

When the script finishes, the report will be displayed. There will be links that allow you to view the data and code in Search Builder.

Note

On the IsFamilyGiver condition, instead of passing a hardwired fund id, we pass in the name of a Setting that holds an indirect reference to the campaign fundid. This setting is named BridgeFundId

Also, on the last Category, we use a condition called ContributionAmountSinceSetting. The parameter called SettingNameWithStartDate is set to a combination pair of Setting names called BridgeSinceDate and BridgeFundId. These are indirect references to the most recent campaign email sending date and the fund id for the campaign.

This way, we can write the code so that it is common to all churches where each church can enter a few settings to customize their scripts.

It is intended that you start with Search Builder to tweak your conditions for each Category. Then if you want to update the BridgeQueryTags file, you can use the Code link to view the code that is used to define and create that Category. Just copy that code displayed and paste over the code you want to update in the BridgeQueryTags script. Then of course run the BridgeQueryTags script again to test.

When you are ready to produce a full set of recipients and categories, change the Debug = True to Debug = False

Automate this Script

To get this script to run every morning automatically, you can put it into the MorningBatch Python script.

Open the existing or create a new Python script called MorningBatch.

Add the following line of code.

model.CallScript("BridgeQueryTags")

Save the script. It will run the next morning during the 4:30 - 5:30 time window. Of course you can always manually run this script whenever you want.

© 2019 TouchPoint Software, LLC.  All rights reserved.