How to make a custom script that will be excuted after the document gets deleted?

I made a custom doctype that has a Serial No linked field. and also added a read-only checkbox (lets call it “programmed”) in the Serial No Document that is unchecked by default.
I added a custom script for the custom doctype. So when it is saved, the linked Serial No will be programmed. but when the custom doctype get deleted, the linked Serial No will be unprogrammed
The delete part is what I’m asking for. as it doesn’t do anything when I use the on_trash trigger

I also tried to make the script from the serial number to count if there is a document for it in the custom doctype list. But the problem that it only updates when I open the Serial No record which I can’t rely on for filtering purposes.

Feel free to ask for more details!
Any help would be appreciated!

I Solve it!

Make it submittable
then use on_submit and on_cancel