Out of curiosity, does anyone know if its possible...
# suitescript
s
Out of curiosity, does anyone know if its possible to add a new row to the end of a sublist when the record is loaded in standard mode? The selectNewLine function only works in dynamic mode whereas the insertLine function works in both standard and dynamic. It seems odd to me that based on the docs that you can only add a new row to the end if you are in dynamic mode only
b
setSublistValue with the line set to whatever the next line should be
s
I tried that on a sales order with 2 existing lines and oddly enough, and oddly enough it adds the line to the beginning of the sublist even though the line number in the code is set to 2
b
what did the code look like
s
Copy code
require(['N/record'], function (record) {
    let rec = record.load({
        type: 'salesorder',
        id: 268913,
        isDynamic: false
    });

    rec.setSublistValue({
        sublistId: 'item',
        fieldId: 'item',
        line: 2,
        value: 11
    });

    rec.setSublistValue({
        sublistId: 'item',
        fieldId: 'quantity',
        line: 2,
        value: 1
    });

    rec.save();
});
and here was the line that got added
b
code works for me
Copy code
require(["N/record"], function (record) {
  var rec = record.load({
    type: "salesorder",
    id: 242,
    isDynamic: false,
  });

  log.debug(
    "old first item",
    rec.getSublistValue({
      sublistId: "item",
      fieldId: "item",
      line: 0,
    })
  );

  log.debug(
    "old first quantity",
    rec.getSublistValue({
      sublistId: "item",
      fieldId: "quantity",
      line: 0,
    })
  );

  log.debug(
    "old third item",
    rec.getSublistValue({
      sublistId: "item",
      fieldId: "item",
      line: 2,
    })
  );

  log.debug(
    "old third quantity",
    rec.getSublistValue({
      sublistId: "item",
      fieldId: "quantity",
      line: 2,
    })
  );

  rec.setSublistValue({
    sublistId: "item",
    fieldId: "item",
    line: 2,
    value: 5,
  });

  rec.setSublistValue({
    sublistId: "item",
    fieldId: "quantity",
    line: 2,
    value: 1,
  });

  rec.save();

  var rec = record.load({
    type: "salesorder",
    id: 242,
    isDynamic: false,
  });

  log.debug(
    "new first item",
    rec.getSublistValue({
      sublistId: "item",
      fieldId: "item",
      line: 0,
    })
  );

  log.debug(
    "new first quantity",
    rec.getSublistValue({
      sublistId: "item",
      fieldId: "quantity",
      line: 0,
    })
  );

  log.debug(
    "new third item",
    rec.getSublistValue({
      sublistId: "item",
      fieldId: "item",
      line: 2,
    })
  );

  log.debug(
    "new third quantity",
    rec.getSublistValue({
      sublistId: "item",
      fieldId: "quantity",
      line: 2,
    })
  );
});
outputs
s
I was originally testing from the browser console which is where I was getting the strange result, but from the debugger it works for me as well