Set local variables in event subprocess via REST-API

Hi,
I have the following model:
grafik

And this Rest API call:

{
    "messageName": "demoMessage",
    "processVariablesLocal": {
        "localVariable": {
            "value": "demo",
            "type": "String"
        }
    },
    "resultEnabled": true
}

I want to set a local variable via REST-API in the event-subprocess.

Following problem occurs:

  • The variable “localVariable” will be set in global process scope
  • With this said, the variable “localVariable” gets overriden every time a new event-subprocess occurs…

My question:

  • Is there any way to set local variables in an event-subprocess via the REST-API at message start?

Currently I found a workaround to set local variables in event subprocess by adding an execution listener to the message start event.

Nevertheless I think that is not a very clean workaround, because every variable from the REST-API call gets saved in global scope and than the execution listener creates a new local variable for it…

Thanks in advance,
Marc

@Marc1 I just tested this out, this looks like a bug (IMO) or at the very least a seemingly undocumented “feature”…

The processVariablesLocal prop indeed does not store it into the local variables of the execution…
Everything seems to be fine in the API side: camunda-bpm-platform/MessageRestServiceImpl.java at master · camunda/camunda-bpm-platform · GitHub

but maybe its a bug with the actual message service? (to be tested)

I also added a variable into the execution manually through the API to confirm that a event sub process will hold execution vars

Okay just tested with a delegate to correlate using the localVariables.

Would say that the config of the builder is not setup in the expected / documented way.

So either a bug or undocumented behaviour

@thorben

Problem looks to be this:

It seems to assume that a Message Correlation will save Process Instance Local Variables rather than Execution Local Variables. In the case the event sub process, it is the same Process Instance ID for the test user tasks, but their execution is different.

I created a jira ticket

https://app.camunda.com/jira/browse/CAM-10380

2 Likes

Thanks for your fast reply and creating a jira ticket! :grinning:

This chunk of code looks exectly like the problem:

look at lines 74 and 75.

It assumes that local variables will go into a process instance scope.

But if you pull your tasks down in the API, you can see the tasks are in the same instance scope, but have different executions.

    {
        "id": "4a4be094-82ec-11e9-b3b2-10653007a178",
        "name": "placeholder",
        "assignee": null,
        "created": "2019-05-30T11:04:58.189-0400",
        "due": null,
        "followUp": null,
        "delegationState": null,
        "description": null,
        "executionId": "86b17455-82ec-11e9-81a9-10653007a178",
        "owner": null,
        "parentTaskId": null,
        "priority": 50,
        "processDefinitionId": "message-test1:1:2bfe75d2-82ec-11e9-81a9-10653007a178",
        "processInstanceId": "4a46d780-82ec-11e9-b3b2-10653007a178",
        "taskDefinitionKey": "Task_06zc4vr",
        "caseExecutionId": null,
        "caseInstanceId": null,
        "caseDefinitionId": null,
        "suspended": false,
        "formKey": null,
        "tenantId": null
    },
    {
        "id": "86b3702b-82ec-11e9-81a9-10653007a178",
        "name": "something",
        "assignee": null,
        "created": "2019-05-30T11:06:39.531-0400",
        "due": null,
        "followUp": null,
        "delegationState": null,
        "description": null,
        "executionId": "86b1e987-82ec-11e9-81a9-10653007a178",
        "owner": null,
        "parentTaskId": null,
        "priority": 50,
        "processDefinitionId": "message-test1:1:2bfe75d2-82ec-11e9-81a9-10653007a178",
        "processInstanceId": "4a46d780-82ec-11e9-b3b2-10653007a178",
        "taskDefinitionKey": "Task_0wy2010",
        "caseExecutionId": null,
        "caseInstanceId": null,
        "caseDefinitionId": null,
        "suspended": false,
        "formKey": null,
        "tenantId": null
    }

Digging a little further:

Its this:

which points to:

which is setting the scope of each variable with:

whihc just points to this

where this is the scaope of the process instance from https://github.com/camunda/camunda-bpm-platform/blob/0d3460bdc55a3d7999e1960db0e1a671a32b7cf0/engine/src/main/java/org/camunda/bpm/engine/impl/cmd/AbstractCorrelateMessageCmd.java#L75, thus seems the problem

1 Like

Hi, I had similar observation and got this feedback from Tobias.

3 Likes

Thanks a lot @pitu72 , this solved my problem.

I am now sending the variables transient via the REST-API to the event-subprocess:

{
    "messageName": "demoMessage",
    "processVariables": {
        "localVariable": {
            "value": "exampleValue",
            "type": "String",
            "valueInfo" : { "transient" : true }
        }
    },
    "resultEnabled": true
}

And then save the variable at message start event locally via execution listener:
grafik

2 Likes

@pitu72 so the docs at the very least should be updated, because it’s non-intuitive but the docs also say “execution”. And a event sub process has the ability to hold local vars as shown above the photo.

1 Like

Hi guys,

What you observe is expected behavior. Please see my explanation in the ticket at https://app.camunda.com/jira/browse/CAM-10380.

Cheers,
Thorben

1 Like

Thanks for the quick feedback @thorben.

Added some further details in the ticket on the logic gymnastics going on with this one

@thorben I have updated the issue further with a explanation of the implications of the current impl and how the docs read vs the impl vs how anyone familiar with the system would understand whats going on.

At the very least, there should be some docs updates to occur in Rest API, Java API, and the Event Sub Process Docs

3 Likes