bvcms/bvcms — pull request #27 by hkouns (2014-02-09 23:06:06+00:00)
Title: SendReport function for sending dynamically generated content in body of email with an UPDATED QueryList function that returns an IEnumerable

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.
The Updated QueryList() returns an IEnumerable instead of a List
QueryList is designed to run a pre-saved query referenced by name which
is passed in as a string in the function call.
The resulting collection of people records (limited to 1000) is returned
as an IEnumerable to that all attributes of the Person record is
accessible

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 UPDATED 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 *
from System.Collections 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("SAVED_QUERY_NAME")
i=0
for person in people:
i = i+1
sb.AppendFormat(fmt0, String.Format("- {0} - " , i))

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

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

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

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

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

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

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

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

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

sb.AppendLine('

')
return sb.ToString()