Can't add child using frappe.model.add_child

Hi all,

I’m having trouble getting the new row to show up in the table. The data is there when I test msgprint the new_row. The row just doesn’t show up in the table.

Thanks for any help!

frappe.ui.form.on("Item", "validate", function(doc, cdt, cdn) {

    var d = locals[cdt][cdn]
    
    frappe.call({
        method:"erpnext.stock.Stock_custom_methods.check_eq_items",
        args: {
            doc: d
        },
        callback:function(r){
            //if(r.message == "item not in table"){
                var new_row = frappe.model.add_child(d, "Quote Item", "engine_compatibility_");
                new_row.name = d.item_code;
                new_row.item_name = d.item_name;
                new_row.item_group = d.item_group;
                new_row.brand = d.brand;
                //}
        }
    });
    refresh_field("engine_compatibility_")
});

Try this:

frappe.ui.form.on("Item", "validate", function(frm) {
    var d = frm.doc;
    frappe.call({
        method:"erpnext.stock.Stock_custom_methods.check_eq_items",
        args: {
            doc: frm.doc
        },
        callback:function(r){
            //if(r.message == "item not in table"){
                var new_row = frm.add_child("engine_compatibility_");
                new_row.name = d.item_code;
                new_row.item_name = d.item_name;
                new_row.item_group = d.item_group;
                new_row.brand = d.brand;
                //}
        }
    });
    refresh_field("engine_compatibility_")
});
2 Likes

Hi @alec_ruizramon1

frappe.call is bydefault asynchronous so you need to add the refresh_field(“engine_compatibility_”) in the callback.

Or you can make the frappe.call synchronous by adding the parameter
async:false

Thanks,
Makarand Bauskar

Not a good idea! Browser is single threaded, so it will freeze all execution at that point.

2 Likes

@rmehta your code sort of works when I placed the refresh_field in the callback as suggested by @makarand_b.

I see the row show up during the freeze when saving, but it disappears as soon as the freeze is over. Nothing happens when the refresh is placed outside the callback.

Thank you both for taking a look at this :smile:

Bump - any chance this can get another quick look? The row appears during the freeze on save, but then disappears.

Thanks.

@alec_ruizramon1 did you ever get this working?

@cpurbaugh You are my hero !!!
1 YEAR LATER :slight_smile: … You made my day!!!

Haha thanks, I am just trying to close up some loose ends in the Custom Script forum :slight_smile: