I want to add child tables dynamically depending on records in another doctype.
@Sajid liaz,
You can add the row in the child table using the append method
e.g.
doc = frappe.get_doc('Sales Order', 'SO-00002')
doc.append('items', {
'company': 'company_name',
'item_code': 'item_code',
'item_name': 'item_name',
'field': 'field_value'
})
doc.save()
where items
is the child table's fieldname.
There are several method to add child in parent doc:
`
import frappe
parent = frappe.get_doc('Sales Order', 'SO-00002')
child = frappe.new_doc("Sales Order Item")
child.update({
'company': 'company_name',
'item_code': 'item_code',
'item_name': 'item_name',
'field': 'field_value'
'parent': parent.name,
'parenttype': 'Sales Order',
'parentfield': 'items'
})
parent.items.append(child)
import frappe
parent = frappe.get_doc('Sales Order', 'SO-00002')
child = frappe._dict({
'company': 'company_name',
'item_code': 'item_code',
'item_name': 'item_name',
'field': 'field_value'
})
parent.items.append(child)
`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With