Hey team, I feel like I’ve solved this before and ...
# suitescript
j
Hey team, I feel like I’ve solved this before and I cannot remember how, now. I have two custom records,
customrecord_wssched
and
customrecord_wssched_item
customrecord_wssched_item
is a child record of
customrecord_wssched
The sublist id of the children on the parent is
recmachcustrecord_wssched_item_wssched
I am trying to write a script to remove all children from the parent. I’m loading the parent, and working backwards from the end of the sublist, I am removing each child one by one using
record.removeLine()
. Then I save my parent record. The issue is that the children are not removed, and I am not sure why. Any suggestions? Here is my code:
Copy code
let sublist_id = 'recmachcustrecord_wssched_item_wssched';



let wssched = record.load({type: 'customrecord_wssched', id: wssched_id, isDynamic: true});

// Reports that there are 470 lines
log.debug({title: 'before removing lines', details: 'linecount is ' + wssched.getLineCount({sublistId: sublist_id})});

for(var si = wssched.getLineCount({sublistId: sublist_id}) - 1; si >= 0; si--)
	wssched.removeLine({sublistId: sublist_id, line: si, ignoreRecalc: true});

// Reports that there are 0 lines
log.debug({title: 'after removing lines', details: 'linecount is ' + wssched.getLineCount({sublistId: sublist_id})});

wssched.save();

// Reports that there are 0 lines
log.debug({title: 'after saving', details: 'linecount is ' + wssched.getLineCount({sublistId: sublist_id})});

// Load the record again.
wssched = record.load({type: 'customrecord_wssched', id: wssched_id, isDynamic: true});

// Reports that there are 470 lines
log.debug({title: 'after reloading', details: 'linecount is ' + wssched.getLineCount({sublistId: sublist_id})});
g
Do you have allow delete flagged on the child record?
💯 1
j
facepalm
thanks guys, I’m an idiot.
this explains why it was working BEFORE and not now, too, since I recreated the child record type from scratch recently. I guess I missed ticking that.
e
One would expect the script to throw an error / warning when attempting to save an invalid operation.
j
RIGHT?
g
That would be nice. But note if you log the rec before/after the removal the lines are indeed removed, just no action on save.
j
Though in NetSuite we learn to expect the Unexpected [error]
🤣 3
🎯 1
e
Me: NetSuite, please save this change
NS: Sure!
Me: Is it saved?
NS: Yes!
Me: It didn't change anything
NS: Obv no 🙂
Me: Why?
NS: ...
c
"Expect The Unexpected" would be a fantastic netsuite dev shirt. Just that phrase and the netsuite logo w/ SuiteScript 2.1 error log screenshot.
take my money 2
🤣 5
j
set up a booth right outside the convention, make a killing
c
I mean it even works amazingly with the 2026 suiteworld theme: "Where big ideas meet real outcomes."
😂 3
c
Can I get an Unexpected [error] shirt as well?
j
We had an unexpected error in college and she graduated college in the spring.
😂 3
e
Sounds like a false positive.
c
"task failed successfully"
😂 1
s
“Record has been changed”… And you?