Retrieving information from a foundset to email out.

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?

Thanks

MerMer

Hi MerMer

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)
}

}
var success = plugins.mail.sendMail(em_To, em_From, em_Subj, em_Detl, em_CC, em_BCC, attach, EmailAuth );

if ( success )
{
doc_type = ‘EM_out’
email_time = application.getTimeStamp()
doc_date = application.getTimeStamp()
controller.saveData()
}
else
{
plugins.dialogs.showErrorDialog( subject, ‘Problem sending Email to: \n \n’ + em_To + ‘\n \n Please check email address’, ‘OK’)
}
}
}
plugins.dialogs.showInfoDialog( ‘Emails Sent’, ‘All emails have been sent from Outbox’, ‘OK’)
application.setStatusText(’ Ready’)
application.updateUI()

Graham Greensall
Worxinfo Ltd

Graham,

Many thanks (again!) . I’ll pick my way through some of your code.

MerMer