Don't submit on before_submit

I need not submit if some condition is true on event before_submit.
It’s possible?

frappe.validated = false; works, but that’s inside of a for condition, I think that’s my problem

  for (i = 0; i < array_timesheet.length; i++){
		task_name = array_timesheet[i]
		$.each (frm.doc.time_logs, function(i, d){
			if (task_name == d.task){
				total_hours += d.hours;
        		method: "frappe.client.get",
        		args: {
            			doctype: "Task",
            			name: task_name,
        		callback: function(r){
                		var task_doc = r.message;
				        total_hours += task_doc.actual_time;
		                if (total_hours > task_doc.expected_time){
			                frappe.throw("Total de horas do projeto excedido! Contate seu Administrator.")
			                frappe.validated = false;
1 Like

I need do a break; the for loop, but I can’t do that cause it’s illegal call break method inside a callback

I would restructure your code so that you only do one callback. Assemble it in an object with your for loop and then pass it once.
Consider using frappe.db.get_value and frappe.db.set_value instead - you’re only looking at one value, why are you collecting the whole record to do that? It’s more expensive but maybe not materially so.

I don’t need set value, just get.
First, I got the values of time_logs table, my array variable will receive the taskxxxx of each row.
Then, I do a get doc for each index of my array variable and compaire if the hours expended is greater then expected, if yes, stop all and do not submit a document.
I’ll do this on python side, so I’ll create a new app and etc…
Thank you for reply

Hi its correct to do this on python, just do frappe.throw() to break, It will stop if something is not correct.

frappe.validated = false; has to be first then frappe.throw("message");

1 Like