Hello, I have a client script that fires on fieldChanged and iterates over the item sublist and updates a field on our Sales Order form.
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*@NModuleScope Public
*/
define(['N/log'],
function(log) {
function fieldChanged(context) {
if (context.fieldId !== 'shippingtaxcode') {
return;
}
var cr = context.currentRecord;
var shippingTaxCode = cr.getValue({
fieldId: 'shippingtaxcode'
});
var lineCount = cr.getLineCount({
sublistId: 'item'
});
for (var i = 0; i < lineCount; i++) {
cr.selectLine({
sublistId: 'item',
line: i
});
var taxCode = cr.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode'
});
if (shippingTaxCode != null && shippingTaxCode !== '' && taxCode !== shippingTaxCode) {
cr.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: shippingTaxCode
});
cr.commitLine({
sublistId: 'item'
});
} else {
cr.cancelLine({
sublistId: 'item'
});
}
}
}
return {
fieldChanged : fieldChanged,
};
});
'shippingtaxcode' is the field that is changing and 'taxcode' is the field being modified in the sublist. The 'taxcode' fields are not being updated, however. I've looked over this code thoroughly and I'm not able to figure out why this doesn't work. I've debugged all the values and everything is there and the values are correct. I'm following the sublist update pattern for dynamic records, I've read the API docs for the CurrentRecord object, I feel like I'm doing everything correctly. Does someone see something in my code that I don't?
I appreciate any help. Thanks!