Make child table field read-only after save

i want to make one child table field read-only after save. i used below code but not work.

frappe.ui.form.on(“Appraisal Goal”, “onload”, function(frm, cdt, cdn){
frm.set_df_property(“score”, “read_only”, frm.doc.__islocal ? 0 : 1);

});

please help me.

thanks

try something like below,

for(var i=0; i<frm.doc.items.length;i++){
    var child = frm.doc.items[i];
    var df = frappe.meta.get_docfield(child.doctype,"score", cur_frm.doc.name);
    df.read_only = frm.doc.__islocal ? 0 : 1;
}
refresh_field("items");

thanks @schilgod, but items is child doctype or filed?.

its child doctype(table), its field name is “items”. It may have different name in your doctype

@schilgod, my is.

child dotype: Appraisal Goal and filed is score.

Is score a field in Appraisal Goal doctype?

yes @schilgod

What is the fieldname name of child table in the doctype?

Like below,

@schilgod, Appraisal is parent doctype and Appraisal Goal is Child doctype. Child table Appraisal Goal is link with Appraisal doctype.

below is Appraisal Doctype. and Child table is link whit this: fieldname is goals.

below is Child doctype: Appraisal. field is score

goals is the fieldname of child doctype
just replace items with goals in the code in my previous reply

Thanks for your help @schilgod, but it is not working. page is disorder, is code indent problem?

for(var i=0; i<frm.doc.goals.length; i++){
var child = frm.doc.goals[i];
var df = frappe.meta.get_docfield(“Appraisal Goal”, “score”, cur_frm.doc.name);
df.read_only = frm.doc.__islocal ? 0 : 1;
}

return_field("goals"); 

do i need to use function?.
frappe.ui.form.on(“Appraisal Goal”, “onload”, function(frm, cdt, cdn)

Yes, it should be in function where you want to run that piece of code

@schilgod, thanks.

1 Like

this code work for me. if any one have same scenario, use below code :

frappe.ui.form.on("Appraisal", "goals_on_form_rendered", function(frm, grid_row, cdt, cdn){
	var grid_row = cur_frm.open_grid_row();
	if(frm.doc.workflow_state === "Waiting Verifying"){
		grid_row.grid_form.fields_dict.score.df.read_only = true;
		grid_row.grid_form.fields_dict.score.refresh();
	}
});
3 Likes