Using setVariable with activityId


#21

Okay then. Thanks for your clear explanation.

Best,
Ashlah


#22

Hi, is there any rest api endpoint for setting a variable at activity scope?


#23

hi. Does this still work?

I am updating a variable in my sub process scope like this:

http://localhost:8080/engine-rest/execution/Task_09wzlbx:5467d99f-bbca-11e8-a5b2-ace2d3a04152#multiInstanceBody/localVariables/caseObject
PUT request
with variable:
{“value” : “someValue”, “type”: “String”}

but it gives me 405 (method not allowed )


#24

Hi @Urvashi_Prasad,

Task_09wzlbx:5467d99f-bbca-11e8-a5b2-ace2d3a04152#multiInstanceBody is not an execute id but an activity instance id, so this request will not work anyway. On top of that, I guess the # symbol also messes up the URL unless you encode it properly.

Cheers,
Thorben


#25

Hi @thorben Can you please tell me a way to add/update a variable on a subprocess scope using REST API?

I have been trying for a while now.
I have posted what all i have tried in this topic.


Thanks


#26

Can anyone please let me know if this feature
https://docs.camunda.org/manual/7.7/user-guide/process-engine/variables/#setting-variables-to-specific-scope
is available through REST API or not.?


#27

Hi Urvashi,

I faced the same scenario where I had to save a variable’s value at a specific scope using REST API,
This is what I found

  1. using https://docs.camunda.org/manual/7.9/reference/rest/process-instance/post-modification (hopefully)
  2. Use a unique key for the variable within a multiInstance Process.
  3. You can do a “jugaad (a flexible approach to solving a problem)” :
    • resolve/complete a task with the variable name eg testVar using rest api.
      Use the code below to save a copy of the variable’s last known value at activity scope
execution.setVariable("testVar",execution.getVariable("testVar"),execution.getCurrentActivity().getId());

OR

execution.setVariableLocal("testVar", execution.getVariable(“testVar”));

#28

Thanks for your response Udit. I ended up doing a similar thing.
Added a process instance variable through rest api, and then use that to post it to sub-process scope.
works for now.


#29

@thorben, I am not sure how #multiInstanceBody should be used. Let’s use the diagram you posted in this diagram. suppose I am in Task (task id = 100) now, and I want to create a variable which can be accessed in the Subprocess(parallel mulit instance) scope. Is it right that the code be like:

execution.setVariable(‘a’, ‘some value’, ‘100#multiInstanceBody’);

I tried this code, but it’s not correct, complaining scope not found.


#30

Hi @liang,

The third parameter must have the following format: <activity ID in BPMN XML>#multiInstanceBody. So let’s say the ID of the activity named Task is task, then the parameter value should be task#multiInstanceBody.

Does that make sense?

Cheers,
Thorben


#31

@thorben, thanks for your response. that makes sense, and it’s my understanding too.

In the Task:

var activityId = execution.getCurrentActivityId()+’#multiInstanceBody’;
execution.setVariable(‘insId’, ‘some value’, activityId);

In above code I will get an error complaining scope not found.


#32

Hi @liang,

Please share a unit test on github reproducing this and I can take a look.

Cheers,
Thorben