I am trying to delete a sublist line with SS2.0 bu...
# suitescript
t
I am trying to delete a sublist line with SS2.0 but the line isn't being removed for some reason. Here is the code I am using: for (var j = 0; j < rec.getLineCount('recmachcustrecord_billpayment_id'); j++) { rec.removeLine({ sublistId: 'recmachcustrecord_billpayment_id', line: j }) } Any idea why the lines aren't being removed?
c
Do you have to save() ?
t
I do rec.save() once I add the other lines on - I shouldn't have to save() before I add other lines for this to work right?
c
no, just save once per script execution
t
The record is in dynamic mode, I wonder if that could be affecting it
b
ill give the general advice: remove backwards
☝️ 1
or include logic to account for the shifting indexes
t
the intent is remove every line on the sublist, based on the lineCount
j
think of what happens to the rest of the lines when you remove 0th line, but now
j
is 1
t
ah, good point
b
well, you can probably simplify that to:
Copy code
while (rec.getLineCount("recmachcustrecord_billpayment_id") > 0) {
  rec.removeLine({
    sublistId: "recmachcustrecord_billpayment_id",
    line: 0
  });
}
👍 1
that said, make sure your custom record allows removing the child from the parent
t
yup, that was the trick! works now - thanks for the help everyone
👍 1