Kostenlose Erstberatung
Dienstag, 19 März 2019 10:37

Set reply-to email address when sending a standard record by email out of NetSuite

Written by

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;
}​
Read 265 times Last modified on Freitag, 24 Mai 2019 07:56

Latest from Georg Walther

SPRECHEN SIE UNS AN!

O NetSuite SuiteCloudDeveloperNetwork rgb 2NetSuite SolutionProvider horiz rgb

Hinweis zum Datenschutz

Wir sind bemüht, Ihnen den bestmöglichen Service auf dieser Seite zu bieten. Damit dies reibungslos funktioniert verwenden wir sog. Cookies. Unsere Datenschutzbestimmungen können Sie unter dem Menu Datenschutz nachlesen.

Ich habe verstanden.