hello guys.. i want to set the sublist values based on the drop-down select.. my code is below ..but its not working. please help me on this /**
@NAPiVersion 2.0
@NScriptType ClientScript
@NModuleScope Public
*/
define(['N/search'],
function(s) {
function setItemFromTestValue(currentRecord) {
var testValue = currentRecord.getValue({
fieldId: 'department'
});
var lines = currentRecord.getLineCount({sublistId: 'item'});
if (!testValue) {
return;
}
var itemSearch = s.create({
type: s.Type.ITEM,
filters: [{
name: 'department',
operator: 'is',
values: [testValue]
}]
});
var items =[];
var resultSet =itemSearch.run();
resultSet.each(function(result) {
items.push(result.id);
return true;
});
for (var i = 0; i < items.length; i++) {
if (items.length != '') {
currentRecord.setSublistValue({
sublistId: 'item',
fieldId: 'item',
line: i,
value: items[i]
});
currentRecord.commitLine({sublistId:'item'});
}}
}
function fieldChanged(context) {
var sublistName = context.sublistId;
var FieldName = context.fieldId;
if (FieldName === 'department') {
setItemFromTestValue(context.currentRecord);
}
}
return {
fieldChanged: fieldChanged
};
});