i want to set the department of the line field as the department of the body field. i have below code, but it does not success.
define(['N/search','N/record','N/currentRecord'],
function (search,record,currentRecord) {
function fieldChanged(context){
var transactionRecord = context.currentRecord;
var transactionType = transactionRecord.type;
var sublistName = context.sublistId;
var changedField = context.fieldId;
try{
if (sublistName === 'item' && changedField === 'item'){
log.debug('entering if');
var headerFieldSearch = transactionRecord.getValue('department');
log.debug('line',context.line);
if(headerFieldSearch){
log.debug('setting headerfield',headerFieldSearch);
transactionRecord.selectLine({
sublistId : 'item',
line : context.line
});
transactionRecord.setCurrentSublistValue({
sublistId : 'item',
fieldId : 'department',
value : headerFieldSearch
//line : context.line
//ignoreFieldChange : true
});
log.debug('set');
transactionRecord.commitLine({
sublistId : 'item'
});
log.debug('committed');
}
}
//transactionRecord.save();
}catch(e){log.debug('error',e);}
}
return{
fieldChanged : fieldChanged
}
}
);