Conclusion
I hope you enjoyed reading about this simple customization. If you need help with customizing NetSuite, please contact Suite Tooth Consulting and we would be happy to help you.
Jaime Requena
–
September 6, 2022
When you create a new transaction (i.e. Sales Order, Invoice), NetSuite will automatically source the “To Be E-mailed” field using the email field from the customer record (See below). This is okay if you just want to send to one email address, but what if you want to send to multiple email addresses? NetSuite does not have a native way to accomplish this. This article will detail how to do this using either a custom record or the contact record and SuiteScript.
This custom record will have two fields.
Add a custom checkbox entity field to the contact record. You would check this box to have the email address show up in the “To Be Emailed” text field.
There is one client script that you can deploy on any transaction record which has a customer and can be emailed (i.e. Sales Order, Invoice).
The code:
/**
*@NApiVersion 2.1
*@NScriptType ClientScript
*/
define(['N/search'], (search) => {
pageInit = (context) => {
if (context.mode === 'create') {
const newRecord = context.currentRecord;
loadEmails(newRecord);
}
}
fieldChanged = (context) => {
const field = context.fieldId;
const currentRecord = context.currentRecord;
if (field == 'entity') {
loadEmails(currentRecord);
}
return true;
}
loadEmails = (newRecord) => {
const customer = newRecord.getValue('entity');
if (customer) {
let emails = [];
/********************************/
/* Option 1 - use custom record */
/********************************/
/*
const customerEmailSearch = search.create({
type: "customrecord_customer_email_address",
filters: [
["custrecord_customer_email_customer", "anyof", customer]
],
columns: [
"custrecord_customer_email_email"
]
});
customerEmailSearch.run().each(function (result) {
emails.push(result.getValue('custrecord_customer_email_email'));
return true;
});
*/
/************************************************/
/* Option 2 - use Contacts from customer record */
/************************************************/
const customerEmailSearch = search.create({
type: "contact",
filters: [
["company", "anyof", customer],
"AND",
["custentity_send_transaction", "is", 'T'],
],
columns: [
"email"
]
});
customerEmailSearch.run().each(function (result) {
emails.push(result.getValue('email'));
return true;
});
const fieldLookUp = search.lookupFields({
type: search.Type.CUSTOMER,
id: customer,
columns: ['email']
});
emails.push(fieldLookUp.email);
let allEmails = emails.join(';');
newRecord.setValue('tobeemailed',true);
newRecord.setValue('email', allEmails);
}
}
return {
pageInit: pageInit,
fieldChanged: fieldChanged
};
});
I hope you enjoyed reading about this simple customization. If you need help with customizing NetSuite, please contact Suite Tooth Consulting and we would be happy to help you.
Do not hesitate to contact us. We’re a team of experts ready to talk to you.