Mandatory Field before workflow action

how can make field (agency_name) mandatory before change next status when choose “Send to agency” action

frappe.ui.form.on('Device Maintenance Card', {
    	
    before_workflow_action: (frm) => {
        if ((frm.selected_workflow_action === 'Send to agency')) 
       
        {
            
          frm.set_value("date_of_receipt_from_agency", frappe.datetime.now_datetime());
            frm.refresh();
            frm.save(); 
           
        }
 }});

thanks in advance

https://docs.erpnext.com/docs/user/manual/en/workflows#3-2-conditions

thank you for the help but i still cant do my idea could you please explain more

Hello @Osk ,

Try will server script.

if doc.workflow_state == "YOUR NEXT WORKFLOW STATE" and not doc.field_name:
   frappe.throw("field_name is mandatory")

Example

if doc.workflow_state == "Approved" and not doc.approver:
   frappe.throw("approver is mandatory")

there is an error in syntax

Hello @Osk ,

write it in server script

i did but unfortunately the field of agency_name was empty but it didn’t prevents me
to fill it there is no validate.

Change DocType Event to Before Save

well done. … thank you for the help