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.
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 += “
”+rawData.getColumnName(colNum)+"
"
body += “
”
#Now, generate the data rows
for row in data:
body += “
”
for col in row:
body += “
” + str(col) + “
”
body += “
”
body += “
”
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.
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:
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]