cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a CUSTOM ActivitiEventType

rutenioh
Champ in-the-making
Champ in-the-making
Good morning,

I am having a problem and I think my best solution is creating a custom ActivitiEventType to handle it.

The issue is, in my process, I have an script task after process starts and I want to know if the task fails to handle the error. For example, if there are compilation errors and I don`t want to surround the code with try/catch because I would have to change all bussiness processes.

If the script task crashes, the process intance is deleted but in my datamodel I have data relative to this, so I want to update if this case happens.

My first solution was to implement a ActivitiEventListener to handle the events, but there isn't this kind of event, if something crashed in an script task. I have seen there is a CUSTOM ActivitiEventType, so I think I can use it but I don´t find documentation about that.

Can you help me?

Thanks.
1 REPLY 1

gdharley
Elite Collaborator
Elite Collaborator

You mention you dont want to use a try/catch block because you would have to change all your code, but even if you create a custom event type, you will need to change your code to throw such an event.

To be perfectly honest, the best approach is to wrap your script code in a try/catch block and throw a BpmnError. You can then catch this with a boundary error catch event and handle any roll back. using this approach, you can also take advantage of compensation events although it sounds as though your use case is relatively simple.

However, if you must dispatch a custom event, take a look at the  ActivitiEventDispatcherTest.java test case.
This demonstrates how to dispatch a custom ActivitiEvent.

Also, the 
EventListenersConfigurationTest.java test case demonstrates how to build a listener for CUSTOM ActivitiEvent's.

Cheers,

Greg