I have a client script and I want to remove a subl...
# suitescript
a
I have a client script and I want to remove a sublist item line with it. The problem is
rec.removeLine
passing it
getCurrentSublistIndex
as the line value sometimes gets an error, particularly if it was an uncommitted inserted line in at the end of a sublist (in the UI the remove button would be disabled) Is there any programmatic way for me to know if a line is removable? If it is not removeable I would want to just cancel the line
e
are you sure you are referencing the line correctly? oftentimes people get tripped up bec they builld a for loop to remove lines from 0 > getLineCount, but in essence if you are removing lines then each subsequent line moves down an index.
a
I am not doing this in a loop. I have a modal that opens up when a line is selected. One of the options I want to give in the modal is to remove the current line. So I am passing it getCurrentSublistIndex which indeed logs the current index. The problem is that removeLine is not a valid function call on a new (uncommitted) line. This can be observed in the Netsuite UI itself. If a new line is added but not committed the cancel button is active, but the remove line is inactive
My objective is to know if this is new line that should just be canceled, or an old line that should be removed
m
Maybe wrap it in a
try/catch
? Pseudocode:
Copy code
try {
  removeLine(lineId);
} catch () {
  cancelLine();
}
a
@Mike Robbins Thanks. I had that thought. Was hoping to avoid that, but I guess it may be my only option The other option I thought of would be to see if the button is disabled by looking in the dom
But yours is probably better
I guess one final option would be to have an hidden checkbox on a line that gets set to true once a line is committed