Setting different drop-down options for child table

How to add different values for each select dropdown options for different rows of a table

Is it possible to set different options for a select dropdown for different child table elements?

Is there a way to write on click for the drop-down in the child table elements?

How exactly would you know which options to be displayed for which rows ?
Do you want to differ the option list based on some other field selected in that row ?

@Zlash65

Yes it depends on the other field selected in that row.

This is the scenario:

I have a custom field “Control BOM” in sales order item. This is of type select. When an item is added in Sales Order, this drop-down is dependent on the item that is added. It actually lists all the BOMs that exist for the item added.

Is “Control BOM” a select field ? Shouldn’t it be a Link field since its linking to BOMs ?
If its a link field, you can use set_query to filter the dropdown list

frm.set_query("control_bom", "childtable_name", function(doc, cdt, cdn) {
		return {
			filters: {
				item: frm.doc.item,
			}
		};
	});

@Zlash65

I tried this:
frappe.ui.form.on(“Sales Order Item”, {
item_code: function(frm, cdt, cdn) {
var row = locals[cdt][cdn];
var item_code = row.item_code;
console.log(“#######-item_code::”+item_code);
frm.set_query(“control_bom”, “Sales Order Item”, function(doc, cdt, cdn) {
return {
filters: {
item: item_code
//item:row ===even this didnt work
}
};
});
}//end of item_code function…
});//end of form…

It’s giving error in the browser console:
TypeError: this.fields_dict[opt1] is undefined

@Zlash65

Even this is giving same erro:
frm.set_query(“control_bom”, “Sales Order item”, function(doc, cdt, cdn) {
return{
filters: [
[‘Item’, ‘item_code’, ‘=’, item_code]
]
}
});

Use the child table name that is in the Sales Order DocType and not the actual name of the child doctype.

frappe.ui.form.on(“Sales Order Item”, {
	item_code: function(frm, cdt, cdn) {
		var row = locals[cdt][cdn];
		var item_code = row.item_code;
		console.log("#######-item_code::"+item_code);
		frm.set_query(“control_bom”, “items”, function(doc, cdt, cdn) {
			return {
				filters: {
					'item': item_code
					//item:row ===even this didnt work
				}
			};
		});
	}//end of item_code function…
});//end of form…

Even this doesn’t help. I create a sales order, add an item, select control BOM.
Add one more item and select control BOM. Till then it works fine. Now if I want to change the control BOM for the first item, the control BOM drop-down is listing the BOMs of the second item.

If I reselect the same Item and then click on control BOM, the list is proper.

The custom script is getting executed when a selection of item is done, not when the control BOM dropdown is clicked.

Is it possible to execute code on click of a select field?