I have 3 doctypes A, B and C (C has a child table). On the basis of a server script in doctype A I want to dynamically insert Doctype C and its child table. Can anyone help me out with this?
Hello,
Do you mean inserting with the use frappe.new_doc()
and append
to the child table?
You might want to take a look at this:
Regards,
Ivan
if doc.second_parent_name:
doc = frappe.get_doc({
“doctype”: “Parent”,
“p_name”: doc.first_parent_name,
“p_num”: 42,
“status”: “Open”,
})
doc.insert()
parent = frappe.get_doc('Parent', doc.first_parent_name)
child = frappe._dict({
'c_name': doc.child_name,
})
parent.c_name.append(child)
This the server script I wrote and its not working atm. So the three doctypes are Parent, Child(Child is a child of parent), Second Parent. I have written this script in Second Parent who’s fields are the same as the ones in Parent And Child.
Hello,
Use parent.append("c_name", child)
and then parent.save()
to take effect.
Regards,
Ivan