What’s in the Box?
The out of the box base approval workflows work very well. But our team had wanted to make a slight change to them. At the very start of the workflow we wanted to block the record and set the record restriction as soon as the record was created. This was mainly for customers, vendors and items. This way, who ever was creating the record would have to get it approved before it could be used anywhere.
If you haven’t seen any of the base workflows, they look something like this:
So we though we would just put an extra step just before the “Approval of a customer is requested”. This step would happen after the record was created. Its responses would be to block the record and set the record restriction.
Above is how we wanted the workflow to end up. After testing a few things we noticed something very strange. If you create a new record, send it for approval. Cancel the approval. Then try to send for approval again. You get a very weird error:
But we were just able to send it for approval before? Why cant we now?
So lets got back and and go through our workflow step by step.
1: The customer record is created, the block the record and add a new record restriction.
2. We request approval on this record. An approval request is created.
3. We cancel the request. Approval request is canceled.
Here is the issue:
4: Request approval on this record, although there is a problem. We are not entering the workflow from the start!!! If we wanted to use this workflow. We would have to delete this record. Create a new one and then send if off for approval. Our workflow doesn’t allow for anything to be re-requested. Because the first step is always record creation. You cant remake the record multiple times, we you can if you delete it, but that’s annoying.
How do we fix this?
Well, there are a few options here.
1: Create two different workflows. One just for blocking and adding the record restriction. And another one for the approval process. Basically take the first step in the workflow above and make it its own workflow.
2:Remove the first step. But add a event subscriber to after record creation and block it then. This loses the ability to be controlled in a workflow. But you could add in settings somewhere else to control this.
What’s the Lesson?
Make sure that you are always entering your workflows from the start. You either need to break the workflow into different pieces, or just remove bits here and there.