Before submit maintenance frappe

im trying to validate if the tic field isnt empty when change status through workflow action but its not working can some buddy help please

thats my code :disappointed_relieved:

frappe.ui.form.on('Maintenance Visit', {
    validate: function(frm) {
        if(frm.doc.status!=='Opened' && frm.doc.tic == null) {
            msgprint('You are only allowed Material Receipt');
            validated = false;
        }
    } 
});

is this a check mark field ?

its a select filed

then replace frm.doc.tic == null by !(frm.doc.tic)

also frm.doc.tic != '' should also work

the custom script is ignoring the first condition

frm.doc.status!==‘Opened’

the form is unable to save even when the status isnt = ‘Opened’

example :

ineed the form when the status is ‘Opened’ and the tic field is empty show a massage and not continue with workflow action

thats my code now its not worked and still not checking the main_status value

frappe.ui.form.on('Maintenance Visit', {
    validate: function(frm) {
        if(!(frm.doc.tic) && frm.doc.main_status !=='Opened') {
            msgprint('You are only allowed Material Receipt');
            validated = false;
        }
    } 
});

ok try this one:

frm.doc.tic != ''

thanks for replay

but still action is moved with out cheeking the condition

Oh I’m sorry it should be == ‘’

frm.doc.tic == ''

im sorry for that :hugs:

but still not working thats my code

frappe.ui.form.on(‘Maintenance Visit’, {
validate: function(frm) {
if(frm.doc.tic == ‘’ && frm.doc.main_status!=‘Opened’) {
msgprint(‘You are only allowed Material Receipt’);
validated = false;
}
}
});

okay replace frm by cur_frm in the code, and try again

try to change the trigger to field name instead of validate

still not worked

ineed the form when the status is ‘Opened’ and the tic field is empty

thanks for reply how can ido that

i also try that with no result

frappe.ui.form.on('Maintenance Visit', {
before_submit: function(frm) {
	if (frm.doc.tic == '') {
		frappe.throw(__("Mandatory field: attach_22"))
	}
}

});

Prevent workflow action is not working. You can try before_workflow_action OR after_workflow_action. I’m also trying to do same. if you get an answer, please share with me.