Hooks on Child Table not working


I am trying to add hooks on Project User child table. I want to send mail to project user when the user is removed from the project.

Hence, I am trying to add hooks in the custom app on “on_trash” doc_event. But it is not working.

Also, I am adding same “on_trash” method in ProjectUser.py in erpnext/projects/doctype/project_user/project_user.py file. but it’s not working too.

Please help!!!

Thank you.

Events only works for parent doctypes.

You have to add hook on project doctype

1 Like

Thanks for the reply saurabh.
but if I add a hook “on_update” of Project doctype, how would I get removed user so that I could send removal email to that user?

Do I have to use “before_insert” event?

I have the same question. Did you ever figure this out?

I figured this out in Javascript. You can use _remove, for example, with a child table field labeled “Company Contact” and named “contacts”:

Use this javascript:

frappe.ui.form.on('Company Contact', {
	contacts_remove: function (form, doctype, id) {
		// console.log(id);
			method: "custom_app.companies.doctype.company.company.remove_company_from_contact",
			args: {
				"company_contact": id
			callback: function(r) {
				if(r.message) {

where your python file has a corresponding function, such as:

def remove_company_from_contact(company_contact):
    company_contact = frappe.get_doc("Company Contact", company_contact)
    contact = frappe.get_doc('Contact', company_contact.contact)
    contact.company = None
    contact.company_role = None
    message = frappe._('Company removed from contact')
    return message
1 Like