// If you find yourself doing something like this...
function fieldChanged(type, name, index) {
if (name == 'salesrep') {
var salesRepId = nlapiGetFieldValue('salesrep');
var salesRepEmail = nlapiLookupField('employee', salesRepId, 'email');
nlapiSetFieldValue('custbody_salesrep_email', salesRepEmail);
}
}
// Stop! and consider using Sourcing for your custom field instead of code
While not strictly a SuiteScript topic, Sourcing is an incredibly powerful feature of NetSuite, and it's an important tool in the toolbelt for any SuiteScript developer. Sourcing allows us to pull data into a record from any of its related records, without writing any code or building a workflow to do so.
Less code is always more maintainable code.
Sourcing is defined on the Sourcing & Filtering tab of a Custom Field definition.