NetSuite scripts often encounter governance limits when processing large datasets or executing multiple transactions. Optimizing governance is essential to ensure script stability and efficiency.
One effective approach is batching records to adhere to governance limits. For example, in Map/Reduce scripts, you can process records in smaller chunks:
define(['N/record', 'N/search'], function(record, search) {
function map(context) {
let records = JSON.parse(context.value);
records.slice(0, 50).forEach(data => {
record.submitFields({
type: record.Type.CUSTOMER,
id: data.id,
values: { email: data.newEmail }
});
});
}
return { map };
});
By handling a subset of records in each batch, you prevent exceeding execution limits, ensuring better performance and reliability.