Is there any quick shortcut way to remove all line...
# suitescript
j
Is there any quick shortcut way to remove all lines from a sublist (in my case, a list of child custom records on a parent custom record)?
doing it line by line is slow and triggering a sublistChanged on every line
a
you can delete the child custom records instead? or break the parent child relationship if you want to keep the records. but that might be slower... I doubt it would trigger sublist changed cos you'd be doing it in the record of the child not the sublist of the parent.
j
yeah I’m deleting in the console for now but that’s also slow, there are like 1400 children
a
when I've done this before I set my loop up to go backwards so the line number reference don't get messed up
j
just looking for a nice solution for the user when they need to clear the list
a
LOL well yeah deleting 1400 records, isn't gonna be quick any way you try to do it.
j
I’ve already written a little mini CSV-import that they can use to populate the sublist from right within the parent record while they are editing, just don’t have an equivalent to clear it out.
on Sales you can clear all lines but I don’t see similar functionality for other sublists
a
what's the issue with sublist changed firing?
could you work around this by having a second sublist maybe? that you copy to the main sublist only on submit? instead of looping thru them all client side?
(i tried inspecting the network calls that are made when you click remove all lines on a sales order - it was basically inscrutable so i gave up)
😂 1
e
No shortcut I'm aware of; you'll have to build it. Personally, for that volume of records, this is not something I'd try to tackle client-side - particularly on a custom sublist since those records exist on their own unlike a transaction line.
j
it’s a rare occurrence that this would come up but still annoying when it does!
e
The SAFE Guide has a strategy for mass create/update of records using Parent-Child relationships, but I don't believe you can delete with the same approach.
^ Maybe you could, if the child record is configured to be deleted when the parent is, but that may not be desirable
s
I'd be curious on what that child record trick does if you remove the lines - does it leave the children abandoned?
e
I would bet it does
but I do not know either
j
That’s a sneaky little trick to do many creates/updates, I didn’t know about that. Makes sense though. Doesn’t really solve my issue but good to know about that!
on a somewhat related note I’ve written my own “Delete Orphaned Records” scheduled script to do cleanup….
I have a child record type where the parent is either a transaction OR an opportunity so I had to make two parent fields (annoying) but when the children get replaced they get left with no parent.