Hello,
We found that sending an email from a standard netsuite transaction does not allow us to modify the reply-to email address. Receipients are confused or do not reply to the email we want to. Here is a workflow action script which fixes this.
NetSuite has an enhancement request, which is currently not in progress. Enhancement # - 76077
var CONST = {
author_license: [some user id],
replyTo: 'set this or pull it from somewhere',
bcc: 'whatever you wish'
}
function sendEmail_WF() {
var po = nlapiGetNewRecord();
var emailMerger = nlapiCreateEmailMerger(yourFormId);
emailMerger.setTransaction(po.getId());
emailMerger.setEntity('vendor', po.getFieldValue('entity'));
var mergeResult = emailMerger.merge();
var subject = mergeResult.getSubject();
var body = mergeResult.getBody();
var recipient = getReceipients(po.getFieldValue('entity'));
if (recipient.length == 0) {
throw 'There is no email address to send this email to.';
}
var attachments = [];
attachments = getAttachment(attachments, po);
attachments = getPDF(attachments, po);
var records = {
transaction: po.getId()
}
if (recipient && recipient != '') {
nlapiSendEmail(CONST.author_license, recipient, subject, body, null, CONST.bcc, records, attachments, null, null, CONST.replyTo);
}
}
function getReceipients(vendId) {
// Here we pull email addresses from the vendor's contacts and also addd the vendor's main email address
var recipient = [];
recipient.push(nlapiLookupField('entity', vendId, 'email'));
var cS = nlapiSearchRecord("contact", null,
[
["company", "anyof", vendId],
"AND",
["custentity_is_po_recipient", "is", "T"],
"AND",
["email", "isnotempty", ""]
]
);
for (var i = 0; cS && i < cS.length; i++) {
recipient.push(cS[i].getId());
}
var recipientNoDupe = [];
recipient.forEach(function (recipient) {
if (recipientNoDupe.indexOf(recipient) < 0) {
recipientNoDupe.push(recipient);
}
});
return recipientNoDupe;
}
function getAttachment(attachments, po) {
varcustbody_your_document_field = po.getFieldValue('custbody_your_document_field');
if (custbody_your_document_field && custbody_your_document_field != '') {
attachments.push(nlapiLoadFile(custbody_your_document_field));
}
return attachments;
}
function getPDF(attachments, po) {
var paras = [];
paras.formnumber = 'your transaction form id';
var file = nlapiPrintRecord('TRANSACTION', po.getId(), 'PDF', paras);
attachments.push(file);
return attachments;
}