1. Invalid Return Data Format**
– **Error**: `INVALID_RETURN_DATA_FORMAT`
– **Example**:
“`javascript
define([‘N/search’], function(search) {
function getInputData() {
return search.create({
type: ‘customer’,
filters: [],
columns: [‘entityid’]
});
}
function map(context) {
// Map logic here
}
function reduce(context) {
// Reduce logic here
}
function summarize(summary) {
// Summarize logic here
}
return {
getInputData: getInputData,
map: map,
reduce: reduce,
summarize: summarize
};
});
“`
– **Solution**: Ensure the `getInputData` function returns a valid search object or an array of key-value pairs.
**Fixed Code Line**:
“`javascript
return search.create({
“`
**2. Exceeding Governance Limits**
– **Error**: `SSS_USAGE_LIMIT_EXCEEDED`
– **Example**:
“`javascript
define([‘N/record’], function(record) {
function map(context) {
var rec = record.load({
type: ‘customer’,
id: context.key
});
rec.setValue({
fieldId: ‘companyname’,
value: ‘Updated Customer’
});
rec.save();
}
return {
map: map
};
});
“`
– **Solution**: Optimize the script to reduce the number of governance units consumed, such as by batching operations or reducing the number of records processed.
**Fixed Code Line**:
“`javascript
rec.save();
“`
**3. Uncaught Error**
– **Error**: `UNEXPECTED_ERROR`
– **Example**:
“`javascript
define([‘N/record’], function(record) {
function map(context) {
try {
var rec = record.load({
type: ‘customer’,
id: context.key
});
rec.setValue({
fieldId: ‘companyname’,
value: ‘Updated Customer’
});
rec.save();
} catch (e) {
log.error(‘Error processing record’, e);
}
}
return {
map: map
};
});
“`
– **Solution**: Add error handling to catch and log errors, preventing the script from failing unexpectedly.
**Fixed Code Line**:
“`javascript
log.error(‘Error processing record’, e);