Select list per row in child table

Hi,
I want to update select list only when item_code field changes is child table.
Every row should have unique select list.
Here’s code.

frappe.ui.form.on('Purchase Order Item', {
	refresh(frm) {
	},
	
	item_code: function(frm, cdn, cdt)
	{
	    var data = locals[cdn][cdt];
	    
	    if (typeof data['item_code'] !== 'undefined')
	    {
            frappe.call({
                method: "frappe.client.get",
                args: {
                    doctype: "Item",
                    name: data['item_code'],
                },
                callback(r) {
                    if(r.message) {
                        var item = r.message;
                        var list = [];
                        
                        $.each(item.supplier_list, function(index, row) {
                            list.push(row.supplier_part_no);
                        });

                        frm.set_df_property('supplier_pn', 'options', list);
                        frm.refresh_fields();
                    }
                }
            });	        
	    }
	}
})

How to do it?

This code updates select list in every row.

var df = frappe.meta.get_docfield("Purchase Order Item", "supplier_pn", frm.doc.name);
                        df.options = list
2 Likes

Anyone?

Thanks a lot!!!

Updating the field metadata is not going to work (as you discovered) because metadata is defined for the child doctype globally, not per instance in a table field. Even if you do change it on the client side, you might run the risk of validation errors going forward.

You could probably do what you’re trying to do with a link field with a custom query, though it’s a bit messy if you’re trying to query child doctypes.