The Store Value setting on the custom field definition plays a very important role in the behaviour of Sourcing:
// 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.
Parameter | Details |
---|---|
Source List | The field on the destination record which links to the source record. You must choose a source list before you can choose your source field. |
Source From | The field on the source record from which data will actually be pulled. The field you choose must match the type of the destination field. For example, if you are sourcing from a Phone Number field, the destination field must be a Phone Number field as well. |