Thursday, November 8, 2018

Send Email through nlapiSendEmail Using the Company Return Email Address

For certain business use cases, users may need to send email or notifications using the Company Return Email Address specified in the Company Information page. Since the nlapiSendEmail only accepts valid Employee internal IDs for the sender parameter, an option is to create a temporary Employee record and then delete it after the email is sent.

function c1464294_S_sendEmail(){
        // Load the Return Email Address from Company Information
        var config = nlapiLoadConfiguration('companyinformation');
        var email = config.getFieldValue('email');

        // Create a temporary employee record with the company email address
        var emp = nlapiCreateRecord('employee');
        emp.setFieldValue('entityid', 'Company A');
        emp.setFieldValue('email', email);
        var id = nlapiSubmitRecord(emp);

        // Send the email and then delete the temporary employee record
        nlapiSendEmail(id, 'recipient@email.com', 'TEST FROM Suitelet', '...using company return email');
        nlapiDeleteRecord('employee', id);
}

No comments:

Post a Comment