Email, HTML, Table Data

Can you provide some examples of how I can do the following:

The user will click on a push button and automatically send an email out to its recipients (already programmed in). The email will need to be HTML and include in its body the data from a table.

Thanks for your support
Derek

To do this, we create the HTML formatted email via a script by looping through the table’s data. It would be nicer if the table had some sort of function like getDataAsHTMLString, but it doesn’t. (This was as of 1.8.7 - the Table component will have this in the next release of FactoryPMI).

For now, a script like the following will create a rudimentary HTML table out of a table component’s data, and email it to someone.

[code]rawData = event.source.parent.getComponent(“Table”).data
data = fpmi.db.toPyDataSet(rawData)

body = “

Here is the table:

#First, generate a header row
body += “


for colNum in range(rawData.columnCount):
body += “"
body += “”

#Now, generate the data rows
for row in data:
body += “


for col in row:
body += “”
body += “”

body += “

”+rawData.getColumnName(colNum)+"
” + str(col) + “

recipients = [“bob@somewhere.com”]
fpmi.net.sendEmail(“mail.company.com”, "me@mycompany.com", “Here is the email!”, body, 1, recipients)
[/code]

You’ll probably have to create the recipients array dynamically based on the results of a query (by running the query with fpmi.db.runQuery)
but this should serve as a useful template.

Hope this helps,

Thanks for your help.
After setting up the smtp, and using the SendAuthEmail
And using the loop information for the body.
IT WORKED.

Now we are just trying to see how we can get the HTML email to work a little better with PDA Phones.

Thanks
Derek

Couple more questions

Also How can I get the user clicking the button to either send the email with the default recipients or to input the recipients in a popup? or maybe an address book (browse) type thing?

When the email button is pressed it takes 20 or 30 seconds before completing the task. 1st How can I change the cursor to indicate that it is working.
2nd How can I pop a pop up message saying the the email task is complete.

The columns that I have selected in the table customizer to be hidden are still being sent in the email. Is there something that I can do to prevent these columns from being sent, probably not because it is not looking at the table’s properties. I would prob have to set up another data set with out these columns?

Well, I suppose you’re going to have to ask the user to make that choice when they click the button. Maybe clicking the button pops up a window that lets the user choose the recipients - just pass the table’s data property into the popup window as a parameter. The popup window could us the List component or another Table component with multi-select to allow the user to select the recipients. This is just an idea - there are many ways you could put this choice together.

Changing the cursor via a script is a little tricky - you need to create the Cursor using Java. Here is an example:

[code]from java.awt import Cursor
event.source.cursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)

Do some long-running task here…

event.source.cursor = Cursor.getDefaultCursor()[/code]

Take a look at the fpmi.gui.messageBox function.

Now, about the ‘hidden’ columns. As you surmised, they are only hidden in the table’s view - they are still in the dataset, which is what our email script uses. The easiest way to omit a column would be to simply modify the script logic to skip a column. For example, the relevant changes to skip the third column would be:

[code]#First, generate a header row
body += “


for colNum in range(rawData.columnCount):
if colNum != 2: # skip the third column
body += “”+rawData.getColumnName(colNum)+""
body += “”

#Now, generate the data rows
for row in data:
body += “


for colNum in range(len(row)):
if colNum != 2: # skip the third column
body += “” + str(row[colNum]) + “”
body += “” [/code]

Hope this helps,