Let's say we have a web application with a form, when we fill the form and click on submit button, it executes the BPMN workflow, then we want to give a success or error message to the user whether that particular action was succeeded or not.
BPMN process:
1. Start event (Give required information)
2. Allocate Consultant (Save data in database)
3. Send email (Send email to relevant parties)
4. Change status (get human interaction to continue the process)
5. another task....
How this executes;
When we start this process, it creates process instance, execute allocate consultant, send email and return response with process instance details, when it hits the user task.
But that response does not contain any information about whether those executed tasks succeeded or not.
Solution:
Let's say when it executes allocate consultant task, it invokes database create operation; if it was failed, we want to give error message, else need to give success message.
So, we can have ErrorBoundryEvent on allocate consultant task; when an error occurred, ErrorBoundryEvent will trigger and continue the error handling flow and returned the process instance details
My trick is, when I start the instance I set a variable error_message = "No_ERROR", if it goes success flow that variable will not changed, if it goes error flow, I will change the variable in set error message script task.
Then when the process instance returned, I make another call and check the value of that error_message variable. and based on that I provide success or error message to the user.
Get the value of error_message variable:
https://localhost:9443/bpmn/runtime/process-instances/{processInstanceId}/variables/error_message
Happy path:
When we start the process instance, we pass variable "errorMessage" with value eg: "NO_ERROR"
execute allocate consultant service task, send email and then when it hits the change status user task, it will return the process instance to the client
Then we do second rest call to check the value of errorMessage.
Error path:
When we start the process instance, we pass variable "errorMessage" with value eg: "NO_ERROR"
if it hit a database error at allocate consultant service task, it will go to the set error message script task, script task will set an error message to the variable errorMessage.
Then bps process instance will return to the client.
Then we do second rest call to check the value of errorMessage.
BPMN process:
1. Start event (Give required information)
2. Allocate Consultant (Save data in database)
3. Send email (Send email to relevant parties)
4. Change status (get human interaction to continue the process)
5. another task....
How this executes;
When we start this process, it creates process instance, execute allocate consultant, send email and return response with process instance details, when it hits the user task.
But that response does not contain any information about whether those executed tasks succeeded or not.
Solution:
Let's say when it executes allocate consultant task, it invokes database create operation; if it was failed, we want to give error message, else need to give success message.
So, we can have ErrorBoundryEvent on allocate consultant task; when an error occurred, ErrorBoundryEvent will trigger and continue the error handling flow and returned the process instance details
My trick is, when I start the instance I set a variable error_message = "No_ERROR", if it goes success flow that variable will not changed, if it goes error flow, I will change the variable in set error message script task.
Then when the process instance returned, I make another call and check the value of that error_message variable. and based on that I provide success or error message to the user.
Get the value of error_message variable:
https://localhost:9443/bpmn/runtime/process-instances/{processInstanceId}/variables/error_message
Happy path:
When we start the process instance, we pass variable "errorMessage" with value eg: "NO_ERROR"
execute allocate consultant service task, send email and then when it hits the change status user task, it will return the process instance to the client
Then we do second rest call to check the value of errorMessage.
Error path:
When we start the process instance, we pass variable "errorMessage" with value eg: "NO_ERROR"
if it hit a database error at allocate consultant service task, it will go to the set error message script task, script task will set an error message to the variable errorMessage.
Then bps process instance will return to the client.
Then we do second rest call to check the value of errorMessage.
Here, in error handling flow, I have used TimerCatchingEvent, after the set error message script task, to wait 1 minute before end the process.
If process instance ends right after setting variable in script task, then when we do the second call there's no instance to get the value of variables. So then we have to make a rest call to BPMN historic data. But if the process goes in happy path then we have to make a rest call to BPMN runtime data. in two cases, we have to do two different calls, and we don't know which one we should call.
So we added intermediate timer catching event in between script task and end event to keep the process instance without killing for 1 minute. during that time we can do the second call and get the value of errorMessage variable from BPMN runtime.
So we added intermediate timer catching event in between script task and end event to keep the process instance without killing for 1 minute. during that time we can do the second call and get the value of errorMessage variable from BPMN runtime.
Comments