bvcms/bvcms — pull request #26 by hkouns (2014-02-09 05:12:11+00:00)
Title: SendReport function for sending dynamically generated content in body of email

I added a new function in PythonEvents.cs to be called from a python
script such as MorningBatch.
EmailReport is designed to be very similar to EmailContent, except that
the body of the email is generated by a python script instead of being
pulled from an static file. The code for the Python Engine was copied from the VitalStats function in QueryFunctions.cs

I also added a support function in QueryFunction.cs. QueryList is
designed to run a pre-saved query referenced by name which is passed in
as a string in the function call.
For each people record returned from the query, we save a series of key
values into a list (PersonList). I just picked a subset of the parameters available on the people record...but I think I got the most general Contact info and data that would be useful in emails... we could always add more later.
The individual lists are combined into a combined list and returned from
the function. These values can then be utilized in the Python Script to generate
custom reports.

This is the function Call I used: (the VitalStats script can be used without any changed)
model.EmailReport("QUERYNAME_RECIPIENTLIST", USERID_QUEUEING, FROM_ADDRESS, FROM_NAME, EMAILSUBJECT, SCRIPT_EMAIL_BODY)

Here is the Python script I used to generate an email listing the contact info of those resulting from a specific saved query:

import System
import System.Text
from System import *
from System.Text import *

class testscript(object):
def Run(self, m):
days = 7

fmt = '
{0}	{1:n0}
\r\n'
fmt0 = '
{0}\r\n'
fmt1 = '

{0}\r\n

'
#fmt = '{0,28}:{1,10:n0}\r\n'
#fmt0 = '{0}\r\n'
sb = StringBuilder()

sb.AppendLine('

')
sb.AppendFormat(fmt1, "Weekly Birthday List", " ")
sb.AppendFormat(fmt0, String.Format("The following people have birthdays in the next {0} days:", days+1))

sb.AppendFormat(fmt, " ", '\r\n')
sb.AppendFormat(fmt, " ", '\r\n')

people = m.QueryList("SAVEDQUERYNAME")

for index in range(len(people)):

sb.AppendFormat(fmt0, String.Format("- {0} - " , index))

person = people[index]

TitleCode = person[0]
Name = person[1]
PrimaryAddress = person[2]
PrimaryAddress2 = person[3]
CityStateZip5 = person[4]
HomePhone = person[5]
CellPhone = person[6]
EmailAddress = person[7]
EmailAddress2 = person[8]
BirthDate = person[9]
BirthDay = person[10]
BirthMonth = person[11]
BirthYear = person[12]
Age = person[13]

if TitleCode is None:
sb.AppendFormat(fmt, Name, " ")
else:
sb.AppendFormat(fmt0, TitleCode + " " + Name, " ")

if PrimaryAddress is not None:
sb.AppendFormat(fmt, PrimaryAddress , PrimaryAddress2 )

if CityStateZip5 is not None:
sb.AppendFormat(fmt, CityStateZip5, "")

if HomePhone != "" and HomePhone is not None:
sb.AppendFormat(fmt0, HomePhone + " (h)", " ")

if CellPhone != "" and CellPhone is not None:
sb.AppendFormat(fmt0, CellPhone + " (c)", " ")

if EmailAddress != "" and EmailAddress is not None:
sb.AppendFormat(fmt, EmailAddress,"" )

if EmailAddress2 != "" and EmailAddress2 is not None:
sb.AppendFormat(fmt, EmailAddress2, "" )

if BirthDate != "" and BirthDate is not None:
sb.AppendFormat(fmt, "Birthday: " + BirthMonth + "/" + BirthDay, "" )

sb.AppendFormat(fmt, " ", '\r\n')

sb.AppendLine('

')
return sb.ToString()