Field Not Updating
In the following code the field ‘custbody_carton_numbers’ is never updated. All the other log.debugs come through perfectly the only issue is that the field is not updating
The second question I have is how do I deploy this script so that it runs on Edit and Create? Right now
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define([‘N/record’, ‘N/log’, ‘N/search’], function(record, log, search) {
function afterSubmit(context) {
try {
log.debug(‘Script Start’, ‘Item Fulfillment After Submit Script’);
// Get the Fulfillment Record ID
let fulfillmentRecord = context.newRecord;
var fulfillmentRecordID = fulfillmentRecord.id;
log.debug(‘Fulfillment Id’, fulfillmentRecordID);
//Create A Search Object
var inventorydetailSearchObj = search.create({
type: ‘inventorydetail’,
filters: [
[‘pickcarton’, ‘isnotempty’, ”],
‘AND’,
[‘transaction.internalid’, ‘anyof’, fulfillmentRecordID]
],
columns: [‘pickcarton’]
});
let searchResultCount = inventorydetailSearchObj.runPaged().count;
log.debug(‘inventorydetailSearchObj result count’, searchResultCount);
let uniquePickcartons = [];
inventorydetailSearchObj.run().each(function(result) {
log.debug(‘Each Result’, result);
let pickCartonValue = result.getValue({ name: ‘pickcarton’ });
if (uniquePickcartons.indexOf(pickCartonValue) < 0) {
uniquePickcartons.push(pickCartonValue);
}
return true; // continue to next result
});
log.debug(‘uniquePickcartons’, uniquePickcartons);
log.debug(‘unique Pick Cartons String’,uniquePickcartons.join(‘, ‘))
fulfillmentRecord.setValue({
fieldId: ‘custbody_carton_numbers’,
value: uniquePickcartons.join(‘, ‘)
});
log.debug(‘Script End’, ‘Item Fulfillment After Submit Script’);
} catch (e) {
log.error({
title: ‘Error in SuiteScript’,
details: e.toString()
});
}
}
return {
afterSubmit: afterSubmit
};
});



