What even is get triggered when we delete an item from a child table?

Hi Everyone,
I need to know which even is get triggered when we delete an item from a child table?

Actually, I want to delete few record from another child table based on this.

See the blow example:

I want to delete few items from the 2nd table when item code 010-001002 get deleted from the 1st table.

I appreciate, if anyone can throw some light on it.
Edit: I got some solution but still it is uncomplete as I am not able to store the value of a row before deleting it:

Solution I got:

frappe.ui.form.on('Sales Order Item', {
    items_remove: function(frm) {
    msgprint("Row Removed!");
    }
});

However, there is another method in the below link, which gets triggered before remove but it is no longer working for me.

https://frappe.github.io/frappe/user/en/guides/app-development/trigger-event-on-deletion-of-grid-row.html

frappe.ui.form.on('Sales Order Item', {
   
 itemsbeforeremove: function(frm) {
    msgprint("Before Remove Called!");
    
    }
});

Any idea how to caputure the value of different fields of the row which gets deleted, so that on that basis I can delete the rows from the another child table.

Regards
Ruchin Sharma

Where you able to find any info on this?

Thanks

Not yet

@ruchin78, @krithi_ramani,

Please check the following links

https://frappe.github.io/frappe/user/en/guides/app-development/trigger-event-on-deletion-of-grid-row

@makarand_b
I have already checked this

fieldnamebeforeremove

doesn’t work and in any other case I don’t get the value of a field/row before deletion.

Regards
Ruchin Sharma

Use the following code as a guide:

var custom = {};
custom.saved_items = [];
custom.added_items = [];

frappe.ui.form.on('Sales Order', {
    onload: function(frm) {
        custom.saved_items = frm.doc.items;
    }
});

frappe.ui.form.on('Sales Order Item', {
    item_code: function(frm) {
        custom.added_items = [];
        // Keep the added items only
        $.each(frm.doc.items, function(i, item) {
            if (item.__islocal) {
                custom.added_items.push(item);
            }
        });
    },
    items_remove: function(frm) {
        // Get the difference between saved items and current items
        var difference = $(custom.saved_items).not(frm.doc.items).get();
        console.log(difference);
    }
});
3 Likes

correct event name is

before_fieldname_remove

ex: before_items_remove

3 Likes

This worked in my case. Thank you

1 Like