Validate Workflow v11

Hi,
this script doesn’t work anymore in v11.

frappe.ui.form.on("Employee Advance", "validate", function(frm) {
if (frm.doc.workflow_state !== "For Approval" && frm.doc.workflow_state !== "Saved")
{

if (frappe.user != frm.doc.project_manager)
   {
   frappe.msgprint("You are not the Approver.");
   throw "Not allowed";
   }

}
});

I had this working in v10.

In v11 it is not even executed. When the workflow_state is “For Approval”, the state is changed by anyone to “Approved” and Submit.

Can anyone provide a solution? Or maybe a better script that works ? :slight_smile:

Just change the event from validation to workflow_state it should work

so I think the problem is somewhere else. Workflow system has changed.

This is our workflow:

and:

When left like this, any Projects Manager member could Approve workflow. I want to limit this to a specific person, hence the script.

But…in v11 there is this change:

This makes it possible for creator to override anything?!? I don’t understand.

The problem is, that if I uncheck this box, I as a creator can’t self approve any workflow, even if I’m member of the Projects Manager group and in our case also project_manager of the project.

But if I leave the box checked, I can approve all workflows and the above script doesn’t work.
Just to be clear, what I changed in script was:
frappe.ui.form.on("Employee Advance", "workflow_state", function(frm) {

can you help please?

So I digged litte bit into this…it seems for my particular case I don’t really need custom js scripts now and I could simple use condition in the workflow.

Question 1: - the below doesn’t work. I don’t really know how to debug this anymore, since it is not in js…and I don’t really know anything about python. Can anyone provie a correct syntax?
The problem is somewhere with frappe.user. If I change it to hard-coded string (just for test one user), it works.

Question 2: for the sake of other user cases, how to solve the initial problem and run js validate scripts on workflows?

2 Likes

Check this - your scripts may not be the source of the problem Help needed to convert this custom script to run in V11

from my research it seems that v11 no longer fires an event during a workflow action I myself am still trying to find an alternative way

have you found any solution? I want to do something similar. when manager rejects an appraisal, I need to show a pop-up to get the reason for rejecting and then move to next state that is draft.

2 Likes