Misc

model.AppendIfBoth(s1, join, s2)
Returns:

the resulting string

Return type:

str

Parameters:
  • s1 (str) – the first string

  • join (str) – the text to join between the two strings

  • s2 (str) – the second string

If both s1 and s2 have values, the concatenation of s1 + join + s2 will be returned, otherwise just s1 is returned.

model.BirthdayList()
Returns:

A list of upcoming birthdays for people in the user’s tracking list

Return type:

List<BirthdayInfo>

Returns a list of upcoming birthdays for people being tracked by the current user. The list includes birthday date, name, and PeopleId for each person.

model.CallScript(name)
Returns:

the output of the script from all the print statements

Return type:

str

Parameters:

name (str) – The name of the Python Script Special Content

model.Content(name)
Returns:

The content

Return type:

str

Parameters:

name (str) – The name of the Content file

model.CreateCustomView(view, sql)
Parameters:
  • view (str) – The name of the custom view to create

  • sql (str) – The SQL query that defines the view

Creates a custom view in the database. This function is restricted to users with both “developer” and “admin” roles. The view name must be a single alphanumeric word. The view will be created in the “custom” schema.

model.CreateQueryTag(name, code)
Returns:

The count of people in the target

Return type:

int

Parameters:
  • name (str) – The name of the QueryTag

  • code (str) – The Search Builder code to be run

This creates a special type of tag called QueryTag. It uses the same table that holds all other tags. But this type is only managed (created and deleted) with a Python script. If QueryTags will be used for multiple purposes, it is important to name the tags with a common prefix for a given purpose or project. This way it will be easy to delete a project’s query tags to start over without disturbing other projects.

model.CsvReader(text)
Returns:

an object to use for reading the csv file

Return type:

CsvHelper.CsvReader

Parameters:

text (str) – The text of the csv content

Example:

csv = model.CsvReader(model.Data.file)
while csv.Read():
    Date = model.ParseDate(csv['Date'])
    Amount = csv['Amount']
model.CsvReader(text, delimiter)
Returns:

an object to use for reading the csv file

Return type:

CsvHelper.CsvReader

Parameters:
  • text (str) – The text of the csv content

  • delimiter (str) – The character used to separate values in the CSV file

Similar to the standard CsvReader but allows specifying a custom delimiter.

model.CsvReaderNoHeader(text)
Returns:

an object to use for reading the csv file

Return type:

CsvHelper.CsvReader

Parameters:

text (str) – The text of the csv content

Example:

csv = model.CsvReader(model.Data.file)
while csv.Read():
    Date = model.ParseDate(csv[0])
    Amount = csv[1]
model.CustomStatementsFundIdList(name)
Returns:

the string with all fundids in a comma separated list.

Return type:

str

Parameters:

name (str) – the name of the FundList

See also

Custom Contribution Statements and /CustomProgramming/TextScripts/CustomFundSets

model.CmsHost
Returns:

The string like “https://bellevue.tpsdb.com” for your church database.

Return type:

str

This is useful for producing links such as:

linktemplate='<a href="{0}/Person2/{1}">{2}</a>'
link = linktemplate.format(model.CmsHost, peopleid, name)
model.Data
Return type:

Dynamic Dictionary object, with keys as properties.

This object is available whenever a Python Script is run.

model.DataHas(key)
Returns:

True if Data has a property for the specified key

Return type:

bool

Parameters:

key (str) – The name of the key (case sensitive)

Example:

Data.Test = "some words"
if DataHas("Test"):
    print Data.Test
model.DebugPrint(s)
Parameters:

s (str) – The string to output for debugging

Outputs a string to the debug console. Used for debugging purposes during script development.

model.DeleteFile(path)
Parameters:

path (str) – The file path to delete

Deletes a file at the specified path. This method only works in debug mode and will throw an exception in production.

model.DeleteQueryTags(namelike)
Parameters:

namelike (str) – The name of the QueryTag using % as wild card(s)

model.Dictionary(s)
Returns:

The value associated with the key, or empty string if not found

Return type:

str

Parameters:

s (str) – The key to look up in the dictionary

Retrieves a value from the script’s dictionary using the specified key.

model.DictionaryAdd(key, value)
Parameters:
  • key (str) – The key to add to the dictionary

  • value (object) – The value to associate with the key

Adds a key-value pair to the script’s dictionary. The value can be a string or any object.

model.DynamicData()
Returns:

a new DynamicData object

Return type:

DynamicData

This function returns a new DynamicData object that can be used in Python to hold data with name/value pairs.

The easiest way to explain is by examples of what it can do. Try the following code:

dd = model.DynamicData()
dd.value1 = "Value one"
dd.value2 = 123
print '<pre>'
print dd
print '</pre>'

When executed the following shows on the screen:

{
    "value1": "Value one",
    "value2": 123
}

So you are able to store arbitrary values into a DynamicData object in a very simple manner. The output of the print statement presents a representation of the data in JSON format.

Try this:

dd = model.DynamicData()
dd.title = 'This is a demonstration of using multiple levels'
dd.lev = model.DynamicData()
dd.lev.str = "This is in the second level"
dd.lev.num1 = 1
dd.lev.num2 = 2
print '<pre>'
print dd
print 'The sum of num1 and num2 is:', dd.lev.num1 + dd.lev.num2
print '</pre>'

When executed the following is printed to the screen:

{
    "title": "This is a demonstration of using multiple levels",
    "lev": {
        "str": "This is in the second level",
        "num1": 1,
        "num2": 2
    }
}
The sum of num1 and num2 is: 3

Note that there are two assignments of a DynamicData object. The second assiment is to dd.lev, a member of the first object. This way, nested heirarchys are simple and can hold complex and organized structures.

Note how dd.lev.num1 clearly shows the heirarchy from the first level (dd) to the second level (lev) through the dot notation (.).

model.DynamicDataFromJson(json)
Returns:

the DynamicData object

Return type:

DynamicData

Parameters:

json (str) – the string of JSON code

Example:

json = '''
{
    "Member": {
        "RowType": "Member",
        "FamilyCnt": 2746,
        "RecurringCnt": 110,
        "MonthlyAmt": 76831.975
    },
    "NonMember": {
        "RowType": "NonMember",
        "FamilyCnt": 2887,
        "RecurringCnt": 20,
        "MonthlyAmt": 8372.175
    },
    "Combined": {
        "RowType": "Combined",
        "FamilyCnt": 5633,
        "RecurringCnt": 130,
        "MonthlyAmt": 85204.15
    },
    "Created": "3/11/19 3:51 PM"
}
'''
data = model.DynamicDataFromJson(json)
print data.Created
print data.NonMember.MonthlyAmt

The two print statements will output the appropriate values.

model.DynamicDataFromJsonArray(json)
Returns:

a list of DynamicData objects

Return type:

List<DynamicData>

Parameters:

json (str) – the JSON array string to deserialize

Converts a JSON array string into a list of DynamicData objects.

model.Draft(name)
Returns:

The body content of the saved draft

Return type:

str

Parameters:

name (str) – The name of the saved draft

Retrieves the body content of a saved draft from Special Content.

model.DraftTitle(name)
Returns:

The title of the saved draft

Return type:

str

Parameters:

name (str) – The name of the saved draft

Retrieves the title of a saved draft from Special Content.

model.ElementList(array, name)
Returns:

a list of string values extracted from the specified property

Return type:

List<string>

Parameters:
  • array (IEnumerable<DynamicData>) – collection of DynamicData objects

  • name (str) – the property name to extract from each object

Extracts a specific property value from each DynamicData object in the collection and returns them as a list of strings.

model.ExecuteSql(sql)
Parameters:

sql (str) – The SQL statement to execute

Executes a SQL statement against the database. This method only works in debug mode and will throw an exception in production.

model.FmtPhone(phone, *prefix)
Returns:

The formatted phone number, e.g. 901-555-1212.

Return type:

str

Parameters:
  • phone (str) – The phone number to format.

  • prefix (str) – *Optional, Goes in front of the formatted number, e.g. (c) for cell phone.

model.FmtZip(zipcode)
Returns:

The zip code formatted with “plus four” (e.g. 38018-2243 )

Return type:

str

Parameters:

zipcode (str) – The zipcode number to format.

model.FormatJson(json)
Returns:

The formatted json

Return type:

str

Parameters:

json (str) – The compressed json string to be formatted

This adds indentation and newlines to a compressed json string making it easier to read.

model.FormatJson(data)
Returns:

The formatted json

Return type:

str

Parameters:

data (dictionary) – The Python object that should be formatted as Json

Works the same as previous except that you pass in a Python object instead of a json string.

model.FromMorningBatch
Returns:

True if this script is being called from the Batch Service.

Return type:

bool

model.GetCacheVariable(name)
Returns:

The value of the cached variable or an empty string if not found

Return type:

str

Parameters:

name (str) – The name of the cache variable to retrieve

Retrieves a value from the ASP.NET cache. Returns an empty string if the variable doesn’t exist or if called from a batch process.

model.HtmlContent(name)
Returns:

The body of the HTML content saved in Special Content > HTML under name.

Return type:

str

Parameters:

name (str) – The name of the content

model.JsonDeserialize(jsontext)
Returns:

The content of the returned result

Return type:

dynamic

Parameters:

jsontext (str) – The JSON text.

model.JsonDeserialize2(jsontext)
Returns:

The content of the returned result

Return type:

List of dynamic: A Python List of Python Dictionary objects

Parameters:

jsontext (str) – The JSON text.

This method is designed to deserialize an array of json objects.

model.JsonSerialize(obj)
Returns:

The object converted into a JSON string

Return type:

str

Parameters:

obj (object) – The object to be converted

Markdown(text)
Returns:

The rendered HTML text

Return type:

str

Parameters:

text (str) – The markdown text

See https://www.markdownguide.org/

model.Md5Hash(text)
Returns:

A hashed string

Return type:

str

Parameters:

text (str) – The string to be hashed

model.PythonContent(name)
Returns:

The Python script content

Return type:

str

Parameters:

name (str) – The name of the Python script

Retrieves the content of a Python script from Special Content.

model.ReadFile(name)
Returns:

The content of the file

Return type:

str

Parameters:

name (str) – The file path to read

Reads the content of a file at the specified path. This method only works in debug mode and will throw an exception in production.

model.RegexMatch(s, regex)
Returns:

The matched text

Return type:

str

Parameters:
  • s (str) – the target string to be searched for a match

  • regex (str) – the Regular Expression pattern to match on

model.Replace(text, pattern, replacement)
Returns:

The new string with all occurrences of pattern in text replaced with replacement.

Return type:

str

Parameters:
  • text (str) – The entire string to be modified.

  • pattern (str) – The special text to be replaced.

  • replacement (str) – The replacement text.

model.ReplaceCodeStr(text, codes)
Returns:

The text with code replacements applied

Return type:

str

Parameters:
  • text (str) – The text to perform replacements on

  • codes (str) – The replacement codes in format “code1=replacement1,code2=replacement2”

Replaces codes in text using the provided replacement mapping.

model.ReplaceQueryFromCode(encodedguid, code)
Parameters:
  • encodedguid (str) – The encoded GUID of the query to replace

  • code (str) – The new query code to replace the existing query

Replaces an existing query with new query code based on the provided encoded GUID.

model.RestDelete(url, headers, *user, *password)
Returns:

The content of the returned result

Return type:

str

Parameters:
  • url (str) – The fully qualified URL of the REST endpoint

  • headers (Dictionary) – The data passed as headers (stored as a Python Dictionary object)

  • user (str) – The optional user name

  • password (str) – The optional password

The user and password are passed as a Basic Authentication string The HTTP verb is DELETE

model.RestGet(url, headers, *user, *password)
Returns:

The content of the returned result

Return type:

str

Parameters:
  • url (str) – The fully qualified URL of the REST endpoint

  • headers (Dictionary) – The data passed as headers (stored as a Python Dictionary object)

  • user (str) – The optional user name

  • password (str) – The optional password

The user and password are passed as a Basic Authentication string The HTTP verb is GET.

model.RestPost(url, headers, obj, *user, *password)
Returns:

The content of the returned result

Return type:

str

Parameters:
  • url (str) – The fully qualified URL of the REST endpoint

  • headers (Dictionary) – The data passed as headers (stored as a Python Dictionary object)

  • obj (object) – The body of the POST method

  • user (str) – The optional user name

  • password (str) – The optional password

The user and password are passed as a Basic Authentication string The HTTP verb is POST.

The obj will be converted to a string and passed to the REST POST endpoint.

The content-type will be set to “application/x-www-form-urlencoded” unless the headers dictionary contains a key “Content-Type”.

model.RestPostJson(url, headers, obj, *user, *password)
Returns:

The content of the returned result

Return type:

str

Parameters:
  • url (str) – The fully qualified URL of the REST endpoint

  • headers (Dictionary) – The data passed as headers (stored as a Python Dictionary object)

  • obj (object) – The body of the POST method

  • user (str) – The optional user name

  • password (str) – The optional password

The user and password are passed as a Basic Authentication string The HTTP verb is POST.

The body will be Serialized into a JSON string.

model.RestPostXml(url, headers, body, *user, *password)
Returns:

The content of the returned result

Return type:

str

Parameters:
  • url (str) – The fully qualified URL of the REST endpoint

  • headers (Dictionary) – The data passed as headers (stored as a Python Dictionary object)

  • body (str) – The XML body of the POST method

  • user (str) – The optional user name

  • password (str) – The optional password

The user and password are passed as a Basic Authentication string The HTTP verb is POST.

The body will be sent as XML content with content-type “text/xml”.

model.SetCacheVariable(name, value)
Parameters:
  • name (str) – The name of the cache variable to set

  • value (str) – The value to store in the cache

Stores a value in the ASP.NET cache with a 1-minute expiration time. This function has no effect when called from a batch process.

model.Setting(name, def)
Returns:

The Setting value

Return type:

str

Parameters:
  • name (str) – The name of the Setting

  • def (str) – The optional default value, an empty string if not passed

model.SetSetting(name, value)
Parameters:
  • name (str) – The name of the setting to set

  • value (object) – The value to store in the setting

Updates or creates a setting in the database with the specified name and value.

model.SpaceCamelCase(s)
Returns:

the string with space separated words at each Capital letter.

Return type:

str

Parameters:

s (str) – the CamelCasedWords string to be expanded.

model.StatusFlagDictionary(flags)
Returns:

A dictionary of status flags

Return type:

Dictionary<string, StatusFlag>

Parameters:

flags (str) – Optional comma-separated list of flag names to filter by

Returns a dictionary of status flags, optionally filtered by the provided flag names.

model.StatusFlagList()
Returns:

A list of all status flags

Return type:

List<StatusFlag>

Returns a list of all status flags defined in the system.

model.SqlContent(name)
Returns:

The SQL content saved in Special Content > SQL Scripts

Return type:

str

Parameters:

name (str) – The name of the script

model.TextContent(name)
Returns:

The text saved in Special Content > Text Content

Return type:

str

Parameters:

name (str) – The name of the text file

model.TagLastQuery(defaultcode)
Returns:

The ID of the created tag

Return type:

int

Parameters:

defaultcode (str) – The default query code to use if running from batch

Tags the results of the last executed query or uses the provided default code if running from a batch process.

model.TitleContent(name)
Returns:

The title attribute of the content saved in Special Content under name.

Return type:

str

Parameters:

name (str) – The name of the content

This is often used to store the Subject of an email represented by the content.

model.Trim(s)
Returns:

The string with leading and trailing whitespace removed

Return type:

str

Parameters:

s (str) – The string to trim

Removes whitespace from the beginning and end of a string.

model.UrlEncode(s)
Returns:

The URL-encoded string

Return type:

str

Parameters:

s (str) – The string to URL encode

Encodes a string to be used safely in a URL.

model.UserName
Returns:

The username of the logged on user running the script.

Return type:

str

model.UserPeopleId
Returns:

The PeopleId of the currently logged in user, or null if not available

Return type:

int?

This property provides access to the current user’s PeopleId.

model.UpdateStatusFlag(flagid, encodedguid)
Parameters:
  • flagid (str) – The ID of the status flag to update

  • encodedguid (str) – The encoded GUID of the query to use for updating the flag

Updates a specific status flag using the results of the specified query.

model.UpdateStatusFlags()

Updates all status flags in the system based on their associated queries.

model.UserIsInRole(role)
Returns:

True or False

Return type:

bool

Parameters:

role (str) – the role to check

model.WriteContentHtml(name, text, *keyword)
Parameters:
  • name (str) – The name of the file

  • text (str) – The HTML content to be written

  • keyword (str) – Optional keyword to associate with the content

This function writes HTML content to an HTML file in Special Content. If the file exists it will be overwritten. Otherwise, a new file is created.

model.WriteContentPython(name, script, *keyword)
Parameters:
  • name (str) – The name of the file

  • script (str) – The Python script to be written

  • keyword (str) – Optional keyword to associate with the content

This function writes Python script content to a Python Script file in Special Content. If the file exists it will be overwritten. Otherwise, a new file is created.

model.WriteContentSql(name, sql, *keyword)
Parameters:
  • name (str) – The name of the file

  • sql (str) – The SQL code to be written

  • keyword (str) – Optional keyword to associate with the content

This function writes Sql content to a Sql Script file in Special Content. If the file exists it will be overwritten. Otherwise, a new file is created.

model.WriteContentText(name, text, *keyword)
Parameters:
  • name (str) – The name of the file

  • text (str) – The text to be written

  • keyword (str) – Optional keyword to associate with the content

This function writes text to a Text file in Special Content. If the file exists it will be overwritten. Otherwise, a new file is created.

model.WriteFile(path, text)
Parameters:
  • path (str) – The file path to write to

  • text (str) – The text content to write to the file

Writes text content to a file at the specified path. This method only works in debug mode and will throw an exception in production.



Latest Update

8/14/2025

Updated with missing functions and alphabetized.