/**
*@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
};
});
Jaime Requena is a seasoned NetSuite Consultant and Solutions Architect, known for delivering WHITE GLOVE service to businesses. With 15+ years of experience and 3x certifications in ERP, Developer, and Admin, Jaime specializes in highly customized NetSuite accounts, transforming operations for 200+ satisfied customers all across the globe.
We aim to bring unmatched expertise and professionalism to your NetSuite initiatives. Let’s talk about how our NetSuite consultancy can make a difference!
It’s Been 4+ Years Now And We Have Worked With Hundreds Of Clients, Building Our Way To The Top, One Happy Client After Another! Their Voices Of Satisfaction Serve As A Testament To Our Success –