In the server side script, I create a JS object to hold the properties which looks something like this:
Code: Select all
var reportObj = {
emailGroup: "CalibrationLogsDueSoon",
emailResource: "CALIBRATIONLOGS_DUESOON_REPORT",
callingForm: form.callingFormName,
callingScript: "CALIBRATIONLOGS_DUESOON_REPORT_BEFOREFORM",
fileAttachment: fileName,
};
sendEmailReport(reportObj);
Code: Select all
function sendEmailReport(reportObj) {
// The properties must be defined!!!!
if (reportObj.emailGroup == null) {
sendAdminEmail("No email group was provided in call to sendEmailReport()","No email group was provided in call to sendEmailReport() which was called by the script " + reportObj.callingScript + (reportObj.callingForm != null ? " that was called by the form " + reportObj.callingForm : ""));
return null;
}
if (reportObj.emailResource == null) {
sendAdminEmail("No email resource was provided in call to sendEmailReport()","No email resource was provided in call to sendEmailReport() which was called by the script " + reportObj.callingScript + (reportObj.callingForm != null ? " that was called by the form " + reportObj.callingForm : ""));
return null;
}
// If the email resource doesn't exist, send an email to the admin because this shouldn't ever happen
if (resources.getResource(reportObj.emailResource) == null) {
sendAdminEmail("Invalid resource name","The email resource " + reportObj.emailResource + " is not valid. It was called by the script " + reportObj.callingScript + (reportObj.callingForm != null ? " that was called by the form " + reportObj.callingForm : ""));
return null;
}
if (reportObj.callingScript == null) {
sendAdminEmail("No calling script was provided in call to sendEmailReport()","No calling script was provided in call to sendEmailReport() which was called by the script " + reportObj.callingScript + (reportObj.callingForm != null ? " that was called by the form " + reportObj.callingForm : ""));
return null;
}
// TO field must always exist. CC may not exist in a lot of cases where its not used
if (fields.getField("TO_RECIPIENTS") == null) {
sendAdminEmail("TO_RECIPIENTS field does not exist in call to sendEmailReport()","TO_RECIPIENTS field does not exist in call to sendEmailReport() which was called by the script " + reportObj.callingScript + (reportObj.callingForm != null ? " that was called by the form " + reportObj.callingForm : ""));
return null;
}
var recipients=getEmailGroupMembers(reportObj.emailGroup);
// getEmailGroupMembers() returns null if emailGroupName is not a valid Intranet email group
if (recipients != null) {
fields.TO_RECIPIENTS.value=recipients[0];
if (fields.getField("CC_RECIPIENTS") != null) {
fields.CC_RECIPIENTS.value=recipients[1];
}
// Include additional To recipients if provided
if (reportObj.additionalToRecipients != null) {
fields.TO_RECIPIENTS.value+=(fields.TO_RECIPIENTS.value != "" ? ";" : "") + reportObj.additionalToRecipients;
}
// Include additional CC recipients if provided
if (reportObj.additionalCCRecipients != null && fields.getField("CC_RECIPIENTS") != null) {
fields.CC_RECIPIENTS.value+=(fields.CC_RECIPIENTS.value != "" ? ";" : "") + reportObj.additionalCCRecipients;
}
// Trigger email with attachment if one was specified
if (reportObj.fileAttachment==null) {
resources.getResource(reportObj.emailResource).sendmail();
} else {
resources.getResource(reportObj.emailResource).sendmail(reportObj.fileAttachment);
}
} else {
// Send an email to the admin if an email group was specified that doesn't exist
sendAdminEmail("Invalid email group","The email group " + reportObj.emailGroupName + " is not valid. It was called by the script " + reportObj.callingScript + (reportObj.callingForm != null ? " that was called by the form " + reportObj.callingForm : ""));
return null;
}
}
The full error is:
Code: Select all
Can't find method com.ebasetech.ufs.runtime.external.api.impl.EmailResourceWrapper.sendmail(org.mozilla.javascript.ConsString). (GLOBAL_FUNCTIONS#830)
Update: I looked back at some of my other code where I call sendMail and realized that sendmail takes an object of attachments not a string. Wrapping the file name with [] so it reads resources.getResource(reportObj.emailResource).sendmail([reportObj.fileAttachment]); fixed the issue for me.