Hi, I want to add a row in my child table using a PUT call of REST API but the problem is it is replacing the contents of the child table with the data of the PUT call. How can we add a new data in the child table without erasing the existing data in the child table?
I haven’t used but you try and check it.
Please use append.
Example:
DocType: Contact
Add email_id in contact email_ids table
test.append('email_ids', {
'email_id': "test@gmail.com"
})
Thank You!
Hmm
Ok.
I was thinking that you set data via the put/push method.
you can define in the body when you enter new data.
I haven’t used it for integration via rest API but I used it in the server script. when doc saves then automatically data inset in contact.
Example:
contact = frappe.get_doc(dict(
doctype = 'Contact',
first_name = "First",
last_name = "Name"
))
mob_mail=contact.save()
mob_mail.append('email_ids', {
'email_id': "test@gmail.com"
})
mob_mail.append('phone_nos', {
'phone': "9876543210",
})
mob_mail.save()
Hi sir. I figured it out. using POST call and direct it to the child doctype I have added a new row.
Fun Fact:
By making an API call to the Child DocTypes directly, then the child’s controller methods (if they exist) are called automatically:
- before_validate()
- validate()
- before_save()
- on_update()
- etc.
This never happens normally. For example, if you add a controller method “before_save()” to 'Purchase Order Item'
or 'Sales Invoice Item'
, they are never referenced when you work from the Frappe/ERPNext browser interface.
But they are called when you make a POST API, like you demonstrated above.
This can be both helpful, but also frustrating. But I thought I’d mention this behavior.
(I’ve spent the past 12+ months battling with Child DocTypes, and trying to make them more flexible and functional, without calling them from inside Parent DocTypes.)