```/** * @NApiVersion 2.0 * @NScriptType UserEve...
# suitescript
p
Copy code
/**
 * @NApiVersion 2.0
 * @NScriptType UserEventScript
 */
define(['N/email','N/runtime'],
    function(email,runtime) {
        function afterSubmit(context) {
            var currentUser = runtime.getCurrentUser().id;
            var invoice = context.newRecord;
            var invoiceId = invoice.getValue("tranid");
            var emailbody = 'An invoice was created with and ID of '+invoiceId+'. Thank you!';
            email.send({
                author : currentUser,
                recipients: currentUser,
                subject: 'Invoice Created',
                body: emailbody
            });
        }
        return {
            afterSubmit: afterSubmit
        }
    });
This script is supposed to send email for every invoice created. But I can't seem to receive an email from my suitescript. Anyone has any idea?
m
If you are testing in sandbox check the email settings. Also you could achieve this using a saved search alert, no need for a script.
p
Thanks @michoel
r
You could also specify the transaction ID in the relatedRecords property which will attach the email to the 'Communications' tab of the Invoice.
Copy code
email.send({
        author: 123,
        recipients: supplierEmail,
        subject: 'PR ' + purchaseOrderRecord.memo + ' is now approved.',
        body: 'Random stuff',
        attachments: [generatedFile],
        relatedRecords: {
            transactionId: purchaseOrderRecord.id,
        },
    });
p
Sure, thanks!