Hi All - I'm trying to add a new email field to tr...
# suitescript
m
Hi All - I'm trying to add a new email field to transaction records and use that field to email the transaction. Duplicating the to be emailed field. I know this can be done in workflow but I'm trying to learn in script. And I'd like to be able to package it up and bundle for later use. I'm hitting an error just getting a basic email to work. Wondering if someone could see where my rookie mistake is. I really appreciate any help.
/**
 
*@NApiVersion 2.x
 
*@NScriptType UserEventScript
 
*/
define(["N/email"], function(email) {
    
function afterSubmit(context) {
        
var currentRecord = context.newRecord;
        
var newEmail = currentRecord.getValue({
            
fieldId: "custbody_8q_2ndemail"
        
});
        
if (!newEmail){
            
return;
        
};
        
if (newEmail){
            
sendEmail(newEmail);
        
}
    
}
    
function sendEmail(email){
        
email.send({
            
author: 5,
            
recipients: newEmail,
            
subject: "test",
            
body: "test"
        
});
    
}
    
return{
        
afterSubmit: afterSubmit
    
};
});