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

how to add different values for each select dropdown options for different rows of a table using custom script.
Currently when i set the drop down for each row using the following code:
var q_options = [];

frappe.model.with_doc(“Quality Checks”, row.specification, function() {
var optiontable= frappe.model.get_doc(“Quality Checks”, row.specification);

	$.each(optiontable.quality_check_option, function(index_child, row_child){
		q_options.push(row_child.options);
	});
	df.options = q_options;
	q_options = null;
});

cur_frm.refresh_field(“readings”);

This code is setting the same values to all the rows of dropdown.

Hi can you explain your usecase why you need to add different values for each select?

Check this thread

I want to perform Quality Inspection for all items that i procure, and for the quality inspection i have the label and the options.
i fetch the label from options from Quality Checks DocType, I am able to fetch the Quality check parameters for each quality attribute in an array. now when i assign the array to the df attribute, it assigns it to all the rows which i dont want. I want to assign different values to each row of options.

Currently the options in each row get assigned to the values of last Quality Check Attribute.

Here is the complete custom script

cur_frm.add_fetch(‘item_code’,‘item_group’,‘item_group’);
frappe.ui.form.on(“Quality Inspection”, “item_group”, function(frm) {

frappe.model.with_doc(“Item Group”, frm.doc.item_group, function() {
var tabletransfer= frappe.model.get_doc(“Item Group”, frm.doc.item_group);
var df = frappe.meta.get_docfield(“Quality Inspection Reading”,“options”, cur_frm.doc.name);

$.each(tabletransfer.quality_parameters, function(index, row){
d = frm.add_child(“readings”);

d.specification = row.specification;
var q_options = [];

frappe.model.with_doc(“Quality Checks”, row.specification, function() {
var optiontable= frappe.model.get_doc(“Quality Checks”, row.specification);

	$.each(optiontable.quality_check_option, function(index_child, row_child){
		q_options.push(row_child.options);
	});
	df.options = q_options;
	q_options = null;
});

cur_frm.refresh_field(“readings”);
});
});
});

1 Like

have seen this. This does not apply the select options to each row.

I’ve done it by setting the value on each child row render. I did it for changing the read only status, but it should also work for other attributes.

frappe.ui.form.on('Document Change Notice Department', {
	form_render:function(frm, cdt, cdn){
		erpnext.document_change_notice.protect_approval_gridform(frm, cdt, cdn);
	}
});

erpnext.document_change_notice.protect_approval_gridform = function(frm, cdt, cdn)  {
	if(frm.doc.docstatus == 1)
	{
		dep_list = frm.doc.approvals || [];
		
		var apps = frm.get_field("approvals");
		var grid_row = apps.grid.get_grid_row(cdn);

		var docfield = grid_row.docfields;
		var dep = frappe.get_doc(cdt, cdn);
		for(var i = 0; i < docfield.length; i++) {
			if(docfield[i].allow_on_submit && dep.manager_id == frappe.user.name && frm.doc.status == 'Under Review')
			{
				docfield[i].read_only = 0;
			}
			else{
				docfield[i].read_only = 1;
			}
		}
		grid_row.refresh();
	}
}
4 Likes

@Vinod_Gangal I am also facing the same issue. Have you found out any solution for this.??

@Vinod_Gangal I have been facing the same problem, any updates on this?

Thanks!

Following Ben’s example I got it to work. Just change the ‘options’ attribute instead of ‘read_only’.

for(var i = 0; i < docfield.length; i++) {
   if(docfield[i].fieldname == "serial_number"){
	   docfield[i].options = new_serial_number_options;
   }
}
grid_row.refresh();