Need dynamic select option in childtable

Credit to this post for helping me come up with a solution:

To clarify further, as well as to update existing rows in case the dynamic options have changed, I did the following:

// Inital Setup, courtesy of linked post's author
frappe.utils.filter_dict(
	cur_frm.fields_dict["YOUR_CHILD_TABLE_NAME"].grid.docfields,
	{ "fieldname":"NAME_OF_SELECT_FIELD_IN_CHILD_TABLE" }
)[0].options = YOUR_LIST_OF_OPTIONS;
	

// Additional code:
// To refresh the existing select fields in the child table when your list of options change.
// The code above only affects new rows in the child table.
const EXISTING_ROWS_IN_CHILD_TABLE = cur_frm.fields_dict["YOUR_CHILD_TABLE_NAME"].grid.grid_rows
for (row in EXISTING_ROWS_IN_CHILD_TABLE) {
	frappe.utils.filter_dict(
		EXISTING_ROWS_IN_CHILD_TABLE[row].docfields,
		{ "fieldname":"NAME_OF_SELECT_FIELD_IN_CHILD_TABLE" }
	)[0].options = YOUR_LIST_OF_OPTIONS_WHICH_HAS_BEEN_EDITED;
}

// Save the changes
cur_frm.refresh();

I run this code during the onload event, as well as any other events where the list of options could change. For instance, in my case, my list of options is from another child table, so I also run the above code when there are new rows or edited values in that child table.

1 Like