Defining a unique variable for a workflow instance

Hello! I just started to study BPMs and Zeebe.
I started doing the user registration process by phone number and got the problem right away. What if the user clicks on the registration button several times, then several instances of the process with the same data are launched.
I would like to control this at the Zeebe level. For example, if when starting a process with the variable “phone” there is already an instance with the same value of “phone” then createWorkflowInstance returned an error (I am working with a zeebe-node). I have not found anything in the documentation to help me. Is there such a feature in Zeebe?
Thanks!

Hi @redspirit,

first, welcome to our Zeebe community :tada:

I would like to control this at the Zeebe level. For example, if when starting a process with the variable “phone” there is already an instance with the same value of “phone” then createWorkflowInstance returned an error (I am working with a zeebe-node).

Message start events can help you to model this workflow.

If a message is published again (i.e. same message name and same correlation key) and the workflow instance is still active then no new instance is created of this workflow. In your case, the “phone” number could be the correlation key of the message. See:

Also, you can set an id when publishing a message. If a message was published before with the same id and the message is still buffered (i.e. TTL + time when the message was published > now) then the command is rejected. In your case, the “phone” number could be the message-id. See:

Does this help you?

Best regards,
Philipp

1 Like

Thanks for the answer!
First option: good solution, but there is a problem. I cannot get an error from such a message. But the logic works right.
Second option: works well and I get an error if the message is still alive. But I don’t like the need to strictly specify the message lifetime. Can I delete the start message when the process is complete?

I found out that Camunda can specify your own instance ID. Unfortunately, this cannot be done in Zeebe.

No. The message is deleted automatically after the TTL is reached. In Zeebe. messages are not directly coupled to workflow instances.

I’m not sure which feature do you mean. Can you point me to it in the documentation?

I mean the business key. https://camunda.com/blog/2018/10/business-key/
I haven’t worked with this, but it seems like it can be used to check for process uniqueness.

No, you cannot assign a key other than as a variable. You also cannot do any checks in the engine between processes.

Yes. That would be another option. Feel free to create a feature request :slight_smile: