Skip to main content

Provide a error/success message to the client while executing BPMN flow

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.


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.











Comments

This is a really informative knowledge, Thanks for posting this informative Information. Software cloud BPM

Popular posts from this blog

How to generate random unique number in SOAP UI request

eg 1: ${=System.currentTimeMillis() + ((int)(Math.random()*10000))} eg 2: ${=java.util.UUID.randomUUID()} ${=java.util.UUID.randomUUID()} ${=System.currentTimeMillis() + ((int)(Math.random()*10000))} - See more at: http://tryitnw.blogspot.com/2014/03/generating-random-unique-number-in-soap.html#sthash.m2S4tUFu.dpuf ${=System.currentTimeMillis() + ((int)(Math.random()*10000))} - See more at: http://tryitnw.blogspot.com/2014/03/generating-random-unique-number-in-soap.html#sthash.m2S4tUFu.dpuf ${=System.currentTimeMillis() + ((int)(Math.random()*10000))} - See more at: http://tryitnw.blogspot.com/2014/03/generating-random-unique-number-in-soap.html#sthash.m2S4tUFu.dpuf

Tips on using environment variables in WSO2 Integration Cloud

Environment variables allow you to change an application's internal configuration without changing its source code. Let’s say you want to deploy the same application in development, testing  and production environments. Then database related configs and some other internal configurations may change from one environment to another. If we can define these configurations as an environment variables we can easily set those without changing the source code of that application. When you deploy your application in WSO2 Integration Cloud, it lets you define environment variables via the UI. Whenever you change the values of environment variables, you just need to redeploy the application for the changes to take effect. Predefined environment variables Key Concepts - Environment Variables   provides you some predefined set of environment variables which will be useful when deploying applications in WSO2 Integration Cloud. Sample on how to use environment variables U se

VFS access SFTP with special character password

Learn WSO2 ESB VFS Transport https://docs.wso2.com/display/ESB481/VFS+Transport When we need to access the FTP server using SFTP, VFS connection-specific URL need to be given as : <parameter name="transport.vfs.FileURI">vfs:sftp://username:p@ssword@ftp.server.com/filePath?vfs.passive=true</parameter> When the password contains a special characters (eg: p@ssword), it gives the following error. 2015-03-27 13:06:03,766  [-]   [PassThroughMessageProcessor-5]  ERROR VFSTransportSender cannot resolve replyFile org.apache.commons.vfs2.FileSystemException: Invalid absolute URI "sftp://username:***@ftp.server.com/filePath?vfs.passive=true". Solution 1: Replace the special characters with the respective hex representation. <parameter name="transport.vfs.FileURI">vfs:sftp://username:p%40ssword@ftp.server.com/filePath?vfs.passive=true</parameter> Char Hex Code ------- -------- [space] %20 &