How to make child table's first row - field read-only dynamically?

I wrote custom script to make the field of first row of the child table read-only but didn’t work.
My code here.

frappe.ui.form.on("Equipment Maintenance", {

    refresh:function(frm){
        var childTable = frm.doc.history_;
        
     
        var firstRow_status = frm.doc.history_[0].status_s;
        console.log(firstRow_status);
        frm.fields_dict.history_.grid.update_docfield_property(firstRow_status.fieldname, "read_only", 1);

        //alert(firstRow_status);
        //var fields = frm.fields_dict.history_.grid;
       
    }
    
});
1 Like

Hi @Prasant_Pant,

Please try it.

frappe.ui.form.on("Equipment Maintenance", {
    refresh: function (frm) {
        var childTable = frm.doc.history_;
        if (childTable && childTable.length > 0) {
            var firstRowStatus = childTable[0].status_s;
            if (firstRowStatus) {
                frm.fields_dict.history_.grid.get_field(firstRowStatus.fieldname).read_only = 1;
            }
        }
    },
});

Please check the doctype name, field name and child table field name and set it in script.
Then reload and check it.

Thank You!

1 Like

@NCP I tried using your code but it didn’t work.

Any solution?

Nope @MAHMOOD_EBRAHIM