Hello everyone, I am trying to send email to emplo...
# suitescript
s
Hello everyone, I am trying to send email to employees through a call to Suitelet but all the emails are being sent to the current user. I am attaching my code as well if anyone can help. Thanks in advance.
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 */
define(['N/file', 'N/render', 'N/record', 'N/email'], function(file, render, record, email) {

    function onRequest(context) {
        try {
            var id = context.request.parameters.id;
            var rec_email = context.request.parameters.c_email;
            var senderId = -5;
            var recipientEmail = [rec_email];
            // var timeStamp = new Date().getUTCMilliseconds();
            // var recipientId = 12;
            var customrec = record.load({
                type: 'customrecord_emp_data_pr_process',
                id: id
            });
            var xmlTmplFile = file.load('Templates/payslipTemplate.xml');
            var renderer = render.create();
            renderer.templateContent = xmlTmplFile.getContents();
            //renderer.setTemplateByScriptId('CUSTTMPL_199_3984753_180');

            renderer.addRecord({
                templateName: 'record',
                record: customrec
            });
            // var xml = renderer.renderAsString();
            var invoicePdf = renderer.renderAsPdf();
            email.send({
                author: senderId,
                recipients: recipientEmail,
                subject: 'Payslip Test',
                body: 'Payslip for this month is',
                attachments: [invoicePdf]
            });
            context.response.write('Email is sent');
        } catch (e) {
            context.response.write(e.message)
        }
    }

    return {
        onRequest: onRequest
    }
});
n
Hello. Can you confirm that this has the right value: rec_email ?
b
sandbox?
👍 2
n
Yeah, Sandbox can be the case as well.
s
No its demo account.
Yes it is right value.