Is multiple workflow for same Document Type can be implemented? How!

Is multiple workflow conditions can be implemented? For an instance, my use case is as follows:

Workflow Type: Leave Workflow.

Situation #1: An employee from production who is reporting to Team Leader, will approve their leave first. Then, approval will be forwarded to HR User/Manager. If HR approves, then it goes to Administrator. The administrator has final decision either to approve it or not.

Situation #2: An employee from designing who is reporting is directly to Administrator, will approve their leave first. Then, approval will be forwarded to HR User/Manager. If HR approves, then it approved.

So, I have brief knowledge about workflow, and able to achieve one of above situation #1. Afraid to implement another situation #2. Because, both have same Document Type i.e. Leave Application. So, which one will work at a time, not having experience with it. One will be active and another one?? No Idea !!

Even I select Leave approver in employee, before Leave approver going to act. ERP has to be decided, which workflow should work for which situation. Might be, I’m missing something. Please put your views, how you manages these situations, will surely help some newbie.

we made it with coding as switch depending on data we switch from work flow to another , it’s like a conditional workflow , but we are trying to do refactor to the code and write less code and depend more on what frappe offers , when the workflow get heavy conditional it goes crazy for you to modify it if you use only coding , @random.1 would help better since he is the workflow specialist in our team .

1 Like

Hi @ahmadRagheb,

Would you mind share the code on how you did conditional workflow ?

Thanks.

@SubhajitDey I was able to achieve this to a high degree using existing workflow transitions rules, workflow states and custom user permissions without writing any code, just a custom script for filter. It is a bit cumbersome and takes a bit of modifications but it kind of works.

Essentially, rather than using multiple workflows for the same doctype, i used department permissions as condition for the workflow transition so in situation 1 above for instance, an employee from production department applies for leave, the team leader who only works in production and whose custom permission is defined in the next transition rules will be notified of the next workflow state.

As i said, this is not fool-proof as a user who does not have departments restrictions will still get notified of same application but since no workflow is defined for that user, the user can not take any action even though user can view application. It is a bit complicated to set up and took me a few weeks to fine tune but it is working at the moment. I hope a better workflow designed by @szufisher which i have tested, which allows for multiple workflows for same doctype will eventually be fine-tuned and accepted to the core.

3 Likes

Brilliant @flexy2ky,

Could you please share the Custom Script you used for your filter?

Thanks.