I am trying to automate my email processes. You gave me the following code to send out an email with a report attached. I have commented out the pertinent instructions, but it does work for 1 report and 1 email if I un-comment the proper lines.
function EmailSelectedReports(five, context, result) {
const _five = five;
// const sendTo = five.field.EmailReportsToKey;
five.log('EmailSelectedReports');
// five.log(`EmailSelectedReports: sendToType = "${five.field.EmailReportsToKey}"`);
// const exportResult = ExportReports(five, sendTo);
// five.showMessage(JSON.stringify(exportResult));
////////////////////////////////////////////////////////////////////////////////////////////////
// Execute the report action
////////////////////////////////////////////////////////////////////////////////////////////////
/*
const reportResult = five.executeAction('Roster', {UserKey: five.variable.UserKey});
if (reportResult.isOk() === false) {
return five.createError(reportResult);
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////
// The reportResult contains a parameter called report, which is the report result in the format
// of a pdf (encoded as data url application/pdf mimetype)
////////////////////////////////////////////////////////////////////////////////////////////////
/*
const mailMergeContext = {SMTPToEmail: five.field.EmailAddress, SMTPToName: "Staff", SMTPAttachments: [reportResult.report]};
const mailResult = five.executeAction('ReportEmail', mailMergeContext);
if (mailResult.isOk() === false) {
return five.createError(mailResult);
}
*/
return five.success('Report has been sent');
}
Now I’m developing a new form to send emails both on-demand and automated. Currently I’m working on the on-demand portion.
I have a table called SelectedReports. My intent is to write a server function to collect reportResult objects in a collection or dictionary object, one object per selected report. I will later use this dictionary to power the mail merge.
ChatGPT thinks the reportResult object is too complex to send back from the server in a JSON object or dictionary, because it has both properties and methods. So the first question is: Is that true, or can I repeatedly, in a server function, call the executeAction for each selected report, then store them in a JSON object to return to the client?
The reason I want to call this server function from the client is that there will be several decisions to make after returning the object, before I actually create the emails and add the appropriate reports to them.
For the on-demand emails, there may or may not be reports to attach. For the 2 types of automated emails, there will be reports to attach. So my plan is to first call a server function to get the exported report(s) information, then either use it or not for sending the emails.
Thanks…