How does business key works?

Hi,

I have been reading lately a lot about business key and trying to utilize it in some of our processes.
Below is my understanding,
Business key is supposed to be unique/per process instance in the context of the given process definition. It is sort of like a replacement key for processInstanceId which can be any custom unique value to make it more user readable than processInstanceId (UUID).

I have read many topics in this forum and couldn’t find answers to my questions. So please assist.

Can we set business key after the instance has been created? If so, how?
Also, according to Submit Task Form API documentation, it is supposed to be unique but I am able to create 2 process instances with same business key? Am I missing something in reading it right?

Please see below screenshot for reference.

Thanks for help

1 Like

@rusiarohit take a look at:

Can we set business key after the instance has been created? If so, how?

no, business must be set at process start.

Also, according to Submit Task Form API documentation, it is supposed to be unique but I am able to create 2 process instances with same business key? Am I missing something in reading it right?

Business key is unique to your purpose: such as a CRM case, Shopping Cart ID, Order ID, etc

See the link above for more details such as alternatives to Business Key, benefits of Key, etc.

@StephenOTT Hey Stephen, I had reviewed that post earlier but other than it saying about it being unique and indexed for better performance. I still don’t find answers to my questions.

I see you also asked for some writeup but nothing very clear.

I don’t think. I had created a sample loan workflow as per the Camunda wiki and I didn’t set business key during the start process but in the next user task its allowing me to modify it(See below screenshot of it being the editable field).

But it seems like its not enforced by Camunda. How am I able to create 2 instances with same business key. If Camunda is not enforcing it there is a possibility of it giving me 2 records.

See the screenshot of main post, I have 2 instances with business Key as “Rohit” consider it being OrderId if I try to query by business key I will get 2 process instance for that same key. Isn’t Camunda supposed to enforce it if it is supposed to be unique?

I am a novice in this BPM world so please ignore if I am being too naive. Thanks again!

-Rohit

Did you set the business key in the Task, and then look to see if it was set in the Cockpit or API?

See the screenshot of main post, I have 2 instances with business Key as “Rohit” consider it being OrderId if I try to query by business key I will get 2 process instance for that same key. Isn’t Camunda supposed to enforce it if it is supposed to be unique?

Based on other explanations from other users and the previous post, the Business key is used to for filtering/finding process instances that are in-common (to the business key).

I not sure why they say it need to be unique. My guess is they mean unique to the Key’s purpose. Meaning that if every process instance has the exact same business key then the purpose of the key lost.

Do you have a specific use case you are trying to achieve?

Yeah, It’s not persisting it. I don’t see it in cockpit.

My requirement is similar to orderId, shoppingCarId only. I wanna give each instance a logical id like “Application-1234”. I am currently using process variables for it but thought if I use business key as it allows uniqueness, indexing and better query than process variable but if it is not putting unique constraint then its no different than process variable for my requirement.

If you want to limit the number of processes that are running based on a variable (such as not allow a second process instance to be created if a current process is running with a specific variable value),
you could look at something like: Limit number of concurrently running instances of a process definition (a sort of similar question someone has a few days ago).

Is there a specific query or API that you are looking to use that does not support filtering by a process variable value?

2 Likes

Yeah. I think this helps. From the same example I found another topic(here) which has couple of nice options. DB one looks neat but it will impact all the processes deployed in that engine. Let me see how they fit in.

Thanks Stephen!

1 Like