Want to clear the value of "Read Only Data Field"

  • I have two data field named " Employee id" and “Employee Name”.

  • " Employee id" is link with doctype Employee . The value of “Employee Name” will be set automatically related to “Employee id”.

  • I want to clear “Employee Name” data field if “Employee id” field is set to blank again.

@nishith custom script to set blank value to field

frm.set_value("field_name", value);
frm.refresh_field("field_name");
1 Like

I know about the solution which have mentioned by you.

But I want to set “Employee Name” to blank again if “Salary Advance for Employee” is set to blank again.

I have used cur_frm.cscript.salary_advance_for_employee event to clear it. But it is not triggering while “salary_advance_for_employee” is blank.

cur_frm.cscript.salary_advance_for_employee = function(doc, dt, dn) {
if (doc.salary_advance_for_employee == None)
{
cur_frm.set_value(“employee_name”, “”)
frm.refresh_field(“employee_name”)
}
}

Should be cur_frm.refresh_field(“employee_name”)

1 Like

It’s ok… But actual issue is that the event “cur_frm.cscript.salary_advance_for_employee” is not triggering while “salary_advance_for_employee” is blank.

You are triggering it on itself, it will not trigger till you change it right, Might want to trigger it on onload or on refresh.

Sorry, but I have to set it on “on change” event of “salary_advance_for_employee”.

@nishith Try troubleshooting it, see what is returned by doc.salary_advance_for_employee

I’m not sure which doctype you are working on, but the rest of the fields should be accurate. Just replace DOCTYPE in the first line with the doctype you are working with. Try it out and see how it goes.

frappe.ui.form.on("DOCTYPE", {
    salary_advance_for_employee: function(frm) {
        if ( frm.doc.salary_advance_for_employee === "") {
            frm.set_value("employee_name", "") {
        else {
            frm.add_fetch("salary_advance_for_employee", "employee_name", "employee_name");
        }
    }
});
2 Likes

Hey, I was facing the same problem. This is what I did:

  1. Created an empty variable
var empty = ""
  1. Passed the empty variable as the value of the field we want to reset
frappe.model.set_value(
        cur_frm.doctype,
        cur_frm.docname,
        "Your_Field_Name",
        empty
      );

This reset the field for me