Try ERPNext Buy Support Partners Foundation

Add rows with values in child table


i need to add rows in child table with values using js,

i tried

frappe.ui.form.on('Batch Packing', {
	refresh(frm) {
    var a = frappe.model.add_child(cur_frm.doc, "Batch Packing", "batch_items");
    a.item_code = item_a;
    a.materials = item_name_a;
    a.unit = uom;


but its not saving, when i refresh the page its discard the old row and insert new one.
also giving me error of pymysql.err.InternalError: (1054, "Unknown column 'batch_no' in 'field list'")
when creating new doc.

NOTE : batch_no is the first field of parent doctype. when i change the first field to another it throws the same error with first field name.

1 Like


To add Child via Code,

cur_frm.add_child("project_item_list"); // childTable Field Name

in my it is project_item_list

and how to fill rows in child table?


var childTable = cur_frm.add_child("project_item_list");

1 Like

Thanks. :+1:

I am doing the same thing above described but getting error.
Cannot read property ‘options’ of undefined

please help.

Share your code.

It is resolved now,can you please help me in How to build HTMl table with a loop by using client side custom script??

You may refer to this page How to create a simple HTML table, and load the content from the other doctype?

frappe.ui.form.on('Target Doctype', 'refresh', function(frm, cdt, cdn){{
     'method': 'frappe.client.get_list',
     'args': {
       'doctype': 'Source DocType',
       'columns': ['*']
       'filters': [['Source DocType', 'link_reference', '=',]]
     'callback': function(res){
         var template = "<table><tbody>{% for (var row in rows) { %}<tr>{% for (var col in rows[row]) { %}<td>rows[row][col]</td>{% } %}</tr>{% } %}</tbody></table>",
        frm.set_df_property('html_fieldname', 'options', frappe.render(template, {rows: res.message});