Extension properties

Hi,

I’ve added to the Start event two properties in the “Properties panel” Extensions tab.
I’ve added an ExecutionListener. I’ve looked through all attributes of the (Delegateexecution) execution, but I cannot find the properties I’ve added. I can see the other predefined properties on the other tabs like Id, Name, documentation…

Is there a way to retrieve these properties programatically?

In our case we have a few use cases for these extended/custom properties, to be used in listeners.

Thanks,
Sorin

Hi Sorin,

you can use the Model API to get the extension elements.

public class ExampleExecutionListener implements ExecutionListener {

  public void notify(DelegateExecution execution) throws Exception {
    StartEvent startEvent = (StartEvent) execution.getBpmnModelElementInstance();

    ExtensionElements extensionElements = startEvent.getExtensionElements();
    Collection<CamundaProperty> properties = extensionElements .getElementsQuery()
      .filterByType(CamundaProperties.class)
      .singleResult()
      .getCamundaProperties();

    for (CamundaProperty property : properties) {
      String name = property.getCamundaName();
      String value = property.getCamundaValue();

     // ...
    }
  }
}

See (1) and (2).

Greetings,
Philipp

2 Likes

Thanks, is working fine.

Hello,

Is there a REST based API that does the same ?

We are trying to add custom variables to each task / activity in the process / case. We would like to retrieve these variables in a separate system using a REST API directly.

Thanks

Hi @nitin,

there is no Rest Api to get the Camunda properties of an element directly. If you need this then you have to build it by your own.

In case of process variables, you can use the Rest Api to retrieve a variable of a process instance / execution.

Best regards,
Philipp

1 Like

Thanks Philipp.

I am trying to set a custom property for each task that is open with a user. I am able to retrieve all the standard properties for a task using REST API, however, the need is that I create a custom variable and retrieve that.

I have looked at the option of using process variables. However, these will flow through the entire process. This particular property will change on a task by task basis.
The major problem with process variables is that there might be multiple open tasks / activities for a BPM / CMMN at a particular time. The process variable will be able to hold only 1 value.

We need our solution to work with tasks / activities for both BPM / CMMN.

Many Thanks

@nitin can you use Task/Local Variables?
Can you provide more information about your use case?

HI Stephen

Kindly share an example of creating custom “Local Variables” ?
I was trying to add a “Property” using “Extensions” for a task in a BPM process. Is it the same as your advice ?

We need to use custom forms when tasks are referred to by external system. So, we need to store something like an “externalFormId” per task.

Many Thanks !

I just noticed that there are no “Extensions” or “Add Property” for tasks / activities in CMMN.

We need this solution to work similarly for both BPM processes, and CMMN.
How can I create custom variable for each task, and access it using REST API ?

Thanks,

Specifically for your Custom Forms use case, have you looked at the Form Key field?

When a external system gets a task, the form key is returned which is any string you provide.

if there are other variables that you are storing, please provide further examples.

Thanks Stephen.

Yes, I did explore the formKey field.
I can store an external Id there which the other system can fetch through REST API.

But IMHO, that limits any future capability where we would like to use “embedded forms” when accessing the same flow withing Camunda. Is there a way that I can use embedded forms, along with passing a custom Id to an external system using formKey ?
I am new to Camunda. Kindly correct me if I am wrong in my understanding.

Thanks & Regards,

1 Like

Interesting use case. Have you thought about just storing a mapping between the formkeys and the external system forms. Could even use camunda dmn for this.

The formId that we need to store is very specific to an external system. So, the same needs to be returned to the calling system one way or the other.

Yes, I explored using DMN table as a mapping table. However, I guess that would need 2 API calls.
One on the task, and then a second API call on the DMN to get the corresponding externalFormId.
Ideally, we would like to achieve it in a single REST API call.

Kindly advise if my understanding of Camunda system is correct.

@nitin I do not think you can do what you want, without at least 2 API calls.

Okay.

No way to create custom variables for a task that may be exposed to the API ?

Regards

Not variables that are stored as Task Properties. You have to do what @Philipp_Ossler mentioned.

You are trying to merge two concepts together (external forms, and embedded Forms) when they were not designed to support both at the same time.

The external system is managed by a separate team.
I would still like to retain some level of control in the long term :slight_smile:

Nevertheless, I did try with Extensions and Process Properties as well.
However, one, they are not accessible in the API.
Also, that is not an option with CMMN
Multiple tasks in a process or case complicates it even further.

I think we should consider giving it as an option where the user might want to have custom properties defined at any level (tasks / activities / BPM process / CMMN case, etc.)

Many thanks for your inputs Stephen and Philipp.

Let me try some workarounds if there is no straight jacket way to handle this !

Best Regards,

@nitin you could create some middleware to do the double API call / logic between camunda and the external system. You could deploy this on the same camunda server as a JAX-RS or just build as some sort of microservice.

This seems like a good idea, Stephen. Thanks for the tip !

I’ll continue my research into all the workarounds, and let’s see what’s the best that I can come up with.

Building and deploying a middleware to handle this scenario could take a while. I am under pressure at the moment to deliver a workable solution quickly.

Many Thanks for all your inputs Stephen.
Appreciate the time that you’ve put in for this discussion!

Thanks & Regards,

@nitin you could build this middleware as a node app in a few hours. see the example: Using/building a "webhook server" for Post /message for a webhook pattern.