Try ERPNext Buy Support Partners Foundation

How to create new document on Validate of another doctype

Hello, I want to create new document for doctype on validate another doctype. Please see attached screenshot In which I am validating Library Transaction doctype but I want to insert a new Article while validating LIbrary Transaction.
PFA
ThanksScreenshot%20from%202020-07-11%2010-19-18

Please let me know if I am doing anything wrong.

Looks fine.

But still I am not able to insert new doc.

Please refer to the following link and see what you missed.

You can also run degubber to verify what happens when LibraryTransaction validated

Or for a quick check just add
print(“Validate”)
frappe.msgprint(“Validate”)

To see if validate is being triggered

yes It is triggered the validate method also executed the insert method but new entry was not made in Article Doctype

Try restarting the bench and clear cache.

I have restarted as well as cleared the cache but no luck.:face_with_thermometer:

try to use doc.insert(ignore_permissions=True)

I just figured out what I was missing.
I had to commit using frappe.db.commit() before calling insert method.
!!SOLVED!!

Can you or anyone explain why have to use frappe.db.commit()?
Because I only use doc.insert(ignore_permissions=True) and it works fine.

Or is it may be because I insert the doc from webform (code in doctype_name.py)?