Set the custom field as mandatory in before_workflow_action in client script

Hello,
I am new in ERPNext and I have a problem with the script below. I am trying to set the custom field as mandatory in client script. The system should check the content of the custom field “problem_code” during before_workflow_action == “Work complete” and if this field is empty then set the field as mandatory and call throw. Unfortunately frm.set_df_property(“problem_code”, “reqd”, 1) or frm.toggle_reqd(“problem_code”,true) not work.

frappe.ui.form.on("Task", {
    before_workflow_action: (frm) => {
        if ((frm.selected_workflow_action === "Work Complete") && (!frm.doc.problem_code))
        {
            //frm.set_df_property("problem_code", "reqd", 1);         
            //frm.toggle_reqd("problem_code",true);

            frappe.throw("Please fill all the mandatory field 'Problem code'.");
            frappe.validated = false;
                
        }

    },
});

Thanks for tips in advance.

Hello @Jiri_Sir,

Please share console output and put console.log in IF condition. Then check condition log is printing or not.

Hello @Hardik_Zinzu ,
thanks for comment.
IF statement is working because frappe throw works.
If I put console.log(‘I am here’) in IF statement then console output print it as you can see in the attached picture. Here can you see the throw too.
Thanks

You can use mandatory depends on in your custom field and add this check.

Hello @mujeerhashmi,
thanks for advise.
I do not know if it is a clear way, but I’ve added the hidden field (check type) in the form.
And in the IF statement I am setting this check field to TRUE (frm.set_value(‘bee_check_rtn’, 1); )
In the next step I have put “bee_check_rtn” to mandatory depends (as you mentioned) in problem_code field.
And it is working now :wink: