I need to retrieve all the records from a foundset and send the results of some of the fields (not all of the fields) in each record to a customer by email.
I am wondering the best way of retreiving and formating the records ready to send out. I presume the method goes through each record one by one and then assigns the required fields to a variable. Finally, it formats the variables within an email to send out to the customer.
As I’m new to programming, is this right? Is there an elegant and quick way to do this in Servoy?
Following chunk of code finds all emails that are in the Outbox then sends each one using data from the individual records and also checking/sending attachments. You can pick out the bits that you need.
// isolate the messages type=‘Outbox’
controller.find()
doc_type = ‘Outbox’
controller.search()
if ( controller.getMaxRecordIndex() >0 )
{
var Count = controller.getMaxRecordIndex()
for ( var i = 1 ; i <= Count ; i++ )
{
application.setStatusText(’ Sending ’ + i + ’ of ’ + Count)
controller.setSelectedIndex(i)
var em_To = forms.docs_EM_.email_to
var em_From = forms.docs_EM_.email_from
var em_Subj = forms.docs_EM_.subject + ’ ’ // prevents email failing with empty subject
var em_Detl = forms.docs_EM_.detail + ’ ’ // prevents email failing with empty detail
var em_CC = forms.docs_EM_.email_cc
var em_BCC = forms.docs_EM_.email_bcc
// check/get attachments
// ----------------------
var attach = new Array()
var AttachSize = id_documents_to_media_doc_id.getSize()
if ( id_documents_to_media_doc_id.getSize() != 0 )
{
for ( var i2 = 0 ; i2 < AttachSize; i2++)
{
var record = id_documents_to_media_doc_id.getRecord(i2+1)
attach[i2] = plugins.mail.createBinaryAttachment(record.me_filename, record.me_blob) //application.readFile(blob_filepath)
}