Trigger event right after submit

Hi all,

I want to trigger event right after submit. However, I can’t not find any event for this in our documentation as well as I search around the code. I want to use this trigger to automatic creating another doctype record after we submit document.

Best Regards,

Hi @Tai_Tran1,

have you tried “on_submit” as in

frappe.ui.form.on("Payment Entry", {
  on_submit: function(frm) {
	frappe.msgprint("This got submitted");
  }
});

Thanks for your answer.

However, on_submit method work for the doc.status = 0, not when I turn to 1. My apps need to run extractly right after the doc.status turn into 1.

It works as @lasalesi said you can verify that by checking the “frm.doc.docstatus” not doc.status
like that:
frappe.ui.form.on(“Purchase Invoice”, {
on_submit: function(frm) {
if(frm.doc.docstatus ==1){
frappe.msgprint(“This got submitted”);
}
}
});

Or you can create trigger in server side script by using hook.py but you have to create custom_app first https://frappe.io/docs/user/en/tutorial/new-app

doc_events = {
	"Purchase Invoice": {
		"after_insert": "custom_app.custom_app.doctype.doctype_name.py_name.xxx"
	},
}

This will run xxx function after Purchase Invoice created.

2 Likes

after_submit is not working ?

doc_events = {
	"Purchase Invoice": {
		**"after_submit"**: "custom_app.custom_app.doctype.doctype_name.py_name.xxx"
	},
}