I would like to create a suitescript that goes into the sales order's "salesteam" sublist and stores the first value from the sublist into a custom body field on the same sales order after saving the sales order. Below is my code. The custom field does has blank value.
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/record'], function(record) {
function afterSubmit(context) {
// Retrieve the current record object
var currentRecord = context.newRecord;
// Retrieve the value from the sublist (in this example, we are using the first line of the 'salesteam' sublist)
var sublistValue = currentRecord.getSublistValue({
sublistId: 'salesteam',
fieldId: 'employee',
line: 0 // Replace 0 with the line number of the sublist item you want to retrieve the value from
});
// Set the value of a custom body field to the value retrieved from the sublist
currentRecord.setValue({
fieldId: 'custbody_salesrep_sublist',
value: sublistValue
});
}
return {
afterSubmit: afterSubmit
};
});