trying to have it such that an email is sent to so...
# suitescript
s
trying to have it such that an email is sent to someone when a new customer record is created. Im getting an unexpected error that i cant figure out.
Copy code
{
  "type": "error.SuiteScriptError",
  "name": "UNEXPECTED_ERROR",
  "message": null,
  "stack": [
    "doSendEmail(N/email)",
    "afterSubmit(/SuiteScripts/afterSubmit_newCustomer_Approval.js:31)"
  ],
  "cause": {
    "type": "internal error",
    "code": "UNEXPECTED_ERROR",
    "details": null,
    "userEvent": "aftersubmit",
    "stackTrace": [
      "doSendEmail(N/email)",
      "afterSubmit(/SuiteScripts/afterSubmit_newCustomer_Approval.js:31)"
    ],
    "notifyOff": false
  },
  "id": "7560594d-942a-4238-906d-636885398952-2d323032322e30342e3038",
  "notifyOff": false,
  "userFacing": false
}
* @NScriptType UserEventScript * @NApiVersion 2.X * @NModuleScope Public */ define(['N/record','N/log', 'N/email'], function (record, log, email) { function afterSubmit(context){ if (context.type !== context.UserEventType.CREATE) return; //Trigger on record CREATE var objRecord = context.newRecord; //Create object const newCustId = objRecord.id; const senderId = 4346; //senderID of "Don't Reply" const recipientEmail = '123@123.com'; //for testing email.send({ author: senderId, recipients: recipientEmail, subject: 'SUBJECT', body: 'BODY.', }); } return { afterSubmit : afterSubmit } });
m
Nothing glaring sticks out for me, but I’d make your senderId a string and your recipients an array.
m
is it senderid an employee?
s
@mattdahse Ill give it a shot but API says
options.author
accepts numbers and
options.recipients
accepts a single string. @Martin Yes i made an employee named "Don't Reply" for this as recommended by someone else last week.