After refresh item codes goes away

Hi,

I have written some code on selection of quantity from table1

frappe.call({
              
        method: "library.update_items.get_items_from_product_set_details",
                args: d1,
callback: function(r) {
                     $.each(r.message, function(i, item) {
                var new_row = frm.add_child("items");
                                    new_row.item_code = item.item_code;
                                    new_row.item_name = item.item_name;
                                    new_row.description = item.description;
                                    new_row.warehouse = "India Finished Goods - miSport";
                    		    new_row.uom = item.stock_uom;
                    		    new_row.conversion_factor = 1;
                    		    new_row.stock_quantity = 1;
                                    new_row.qty = item.qty*d.quantity;
                                    new_row.rate = 0;
                                    new_row.amount = 0;
                                    new_row.product_type = d.product_name;
                   });
                    refresh_field("items");
                      
               
                    }

});

This is how it looks like after this code:

And then I have written another code on the value change event of table2

var new_row1 = frm.add_child("items");
new_row1.item_code = item.item_code;
new_row1.item_name = item.item_name;
new_row1.description = item.description;
new_row1.warehouse = "India Finished Goods - miSport";
new_row1.uom = item.stock_uom;
new_row1.conversion_factor = 1;
new_row1.stock_quantity = 1;
new_row1.qty = item.accessories;
new_row1.rate = 0;
new_row1.amount = 0;
new_row1.product_type = "accessories";
refresh_field("items");

This is how it looks like after the above code:

Issue is with refresh_field("items");

If I do refresh_field("items"); then other items goes off and if I do not do refresh_field("items"); then the item details added in the last row doesn’t get display.

NOTE: Till the time data hasn’t be saved in database and document is still in the New Sales Order 1 Stage.

Any idea how this problem can be resolved?

Regards
Ruchin Sharma

Can you share more code? When are you adding rows?

@netchampfaris
Here is my code where I am adding a single row

frappe.ui.form.on("Shipping List", "accessories", function(frm, cdt, cdn){
var d= locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "order_total",d.one1+d.video1+d.accessories);

var item= locals[cdt][cdn];


if(item.accessories>0)
{
$.each(frm.doc.items || [], function(i,item1) {
	if(item1.item_code=item.item_code && item1.product_type=="accessories")
	{	
		cur_frm.get_field("items").grid.grid_rows[i].remove()
	}
});
var new_row1 = frm.add_child("items");
new_row1.item_code = item.item_code;
new_row1.item_name = item.item_name;
new_row1.description = item.description;
new_row1.warehouse = "India Finished Goods - miSport";
new_row1.uom = item.stock_uom;
new_row1.conversion_factor = 1;
new_row1.stock_quantity = 1;
new_row1.qty = item.accessories;
new_row1.rate = 0;
new_row1.amount = 0;
new_row1.product_type = "accessories";
cur_frm.refresh_field("items");
}
else
{
$.each(frm.doc.items || [], function(i,item1) {
	if(item1.item_code=item.item_code && item1.product_type=="accessories")
	{	msgprint("Matched...");
		cur_frm.get_field("items").grid.grid_rows[i].remove()
	}
refresh_field("items"); 
});
}
refresh_field("order_total");
});

Regards
Ruchin Sharma

Any one, any idea about this?

Regards
Ruchin Sharma