I am tring to trigger an event to save doctype data based on another doctype

How can i create item?

If i save book doctype, then auto create item

Hi @RahemanAli_Lal,

If you created custom app then you can apply logic using server script.

Please apply the server script in your custom app.

add in hooks.py

doc_events = {
	"Book": {
		"on_submit": "custom_app.custom_app.doc_events.insert_item",
	}
}
import frappe

def insert_item(doc, method):
    item = frappe.new_doc("Item")
    item.item_code = doc.book_code
    item.item_name = doc.title
    item.item_group = doc.book_category
    # another field, if you want to add
    item.save()

field set/change your field name according to the scenario.

Otherwise, if you don’t want to enter the code in your custom app then you can apply it on the server script doctype. Please explore the reference:

I hope this helps.

Thank You!

2 Likes

Thanks