hello guys.. i want to set the sublist values base...
# suitescript
m
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 }; });
b
state your error up front
you should be doing things like selecting the new line, using setCurrentSublistValue, and then commit the line