BDM Unique Constraint for Active Processes only
Hello,
I have a process in which each process instance has a BDM object associated with it. If a process has started with a BDM object, I want to prevent users from being able to start another process using the same object as the existing process. If I use a unique constraint on the ID field of my BDM object, users are prevented from ever being able to start a process using an object that was used in the past, which is not what I want. I only want to ensure that a process cannot be started using an object that is being used in an active process.
I know I can accomplish this by getting all active process instances, then looping through each instance, get the execution context for each instance, then get the BDM data reference object, call the object dao to get the object, and finally check if the current process a user is attempting to start requires the same object, but this seems very indirect and inefficient.
Perhaps there is a way to easily associate an ID with a process instance?
I like the concept of "Process Variables" or "Search Keys" but see no way of exposing these through the Java API.
I'd greatly appreciate any ideas.
Thanks
Based on your use case maybe you can add an attribute on your business object to flag him as being "updated" by a process instance? This attribute might be for example the id of the process instance currently updating the business process data. You should set this attributes value at the beginning of the process after making sure that it is empty and clear it at the end of the process.
Once you defined such attribute, on the instantiation form of your process you can then use the business data information to prevent user from starting a process if the select business variable as the process instance id attribute set. You can also enforce search restriction in the process definition itself to end the process if the process instance id attribute of your business variable is not empty.
I create an example to illustrate my solution.
Comments
I'm not sure I understand correctly your use case. When your process start:
Thanks for the clarification.
Hello,
I'm starting my process with my unique id being the primary key of my business data. Currently I am using the Search Keys to accomplish what I want, but I am aware this is not the intended use of Search Keys. I have defined the search key of my process as my business data id. In my code, I have a this method:
private boolean checkIfAlreadyInWorkflow(Integer businessObjectId) {
return processAPI
.getProcessInstances(0, -1, ProcessInstanceCriterion.DEFAULT)
.stream()
.anyMatch(processInstance -> {
return businessObjectId.toString()
.equals(processInstance.getStringIndex1());
});
}
I call this before I start new processes just to make sure 2 processes cant start with the same id at the same time.