Anyone know the specific function or process to ad...
# suitescript
u
Anyone know the specific function or process to add a row in a sublist *in SS2? Context is i've added a sublist via
context.Form.addSublist()
, and have successfully added fields with values, but have not found any documentation regarding adding "lines" or rows to it.
b
Sublist.setSublistValue on the line you want to set
same as a record in standard mode
u
for context, I'm inserting a sublist in a record that mirrors a pre-existing sublist with values. As an example, the pre-existing sublist has three lines with values in each field. When I run this specific code block with the intent of "mirroring" the sublist,
Sublist.setSublistValue()
doesn't insert another row past the first one.
Copy code
var _r = record.load({ 
  type: "customrecord_slip", 
  id: _id
});
var _sub = _r.getSublist({ 
  sublistId: "recmachcustrecord_rec2"
});
var linecount = _r.getLineCount({ 
  sublistId:'recmachcustrecord_rec2' 
});

var slist = _f.addSublist({
  id : 'custpage_sublistid',
  type : ui.SublistType.LIST,
  label : 'Test Sublist'
});

      for(var i = 0; i < linecount; i++) {

		if(i == 0) {
          var sublist1 =  slist.addField({ id: 'sl_' + i + '_a', type: ui.FieldType.TEXT, label: 'Item' });
          var sublist2 =  slist.addField({ id: 'sl_' + i + '_b', type: ui.FieldType.TEXT, label: 'Reference' });
          var sublist3 =  slist.addField({ id: 'sl_' + i + '_c', type: ui.FieldType.TEXT, label: 'Quantity' });
          var sublist4 =  slist.addField({ id: 'sl_' + i + '_d', type: ui.FieldType.TEXT, label: 'Address' });
          var sublist5 =  slist.addField({ id: 'sl_' + i + '_e', type: ui.FieldType.TEXT, label: 'Date' });
        }

        var getVal1 = _r.getSublistValue({ sublistId:'recmachcustrecord_rec2',fieldId:'custrecord_tslipc_a',line:i });
        var getVal2 = _r.getSublistValue({ sublistId:'recmachcustrecord_rec2',fieldId:'custrecord_tslipc_b',line:i });
        var getVal3 = _r.getSublistValue({ sublistId:'recmachcustrecord_rec2',fieldId:'custrecord_tslipc_c',line:i });
        var getVal4 = _r.getSublistValue({ sublistId:'recmachcustrecord_rec2',fieldId:'custrecord_tslipc_d',line:i });
        var getVal5 = _r.getSublistValue({ sublistId:'recmachcustrecord_rec2',fieldId:'custrecord_tslipc_e',line:i });

        var setval1 = slist.setSublistValue({ id:'sl_' + i + '_a', line: i, value: getVal1});
        var setval2 = slist.setSublistValue({ id:'sl_' + i + '_b', line: i, value: getVal2});
        var setval3 = slist.setSublistValue({ id:'sl_' + i + '_c', line: i, value: getVal3});
        var setval4 = slist.setSublistValue({ id:'sl_' + i + '_d', line: i, value: getVal4});
        var setval5 = slist.setSublistValue({ id:'sl_' + i + '_e', line: i, value: getVal5});
      }
Am I missing a specific step here?
b
your field ids for your sublist arent sane
1
log the ids of the fields you are creating
and the fields you are setting
u
I see the issue now; an oversight in my planning for the for loop. Thanks.