Completed Job Variables are scoped to processInstance

so when i complete a job like so

client.newCompleteCommand(job)
              .variables(variables)
              .send()

These variables ALL, without any filtering or mapping, end up in my processInstance scope, and therefore in the processVariables i show

also overwriting occurs if this type of job is used multiple times in a flow

i think its the broker who assigns scope, so therefore posting here.
i’m currently workarounding by prefixing variables so i can ignore those when showing variables to a user, but overwriting still occurs and… well its a workaround not a fix

imho these should be locally scoped to the job or element the job was started from. so you then can use the output mapping of the job-element to actually decide whether or not to ‘export’ any variables to to parent-scope.

Hi @arjan_speakup,

I’ve double-checked the docs on local variables, and they are not clear as they could be.

But in real life it’s quite easy: If you define a variable with an input mapping on an embedded subprocess, the variable is local in this subprocess (or call activity or multi instance activity). You can set it as a variable in your worker, as you already do.

All variables will be sorted to their scopes automatically. If they exist in a local scope (from an input mapping), they will be saved there. If they didn’t exist, they will be saved on the process instance scope.

This approach would lead to a lot of required process modelling and adding a lot of output mappings. From my experience, local variables are less used than process variables. Usually, the result of an activity is required as input in a following activity.

Hope this helps, Ingo

it turns out same goes for defining ‘any’ output variable…

so i had the same service task defined 3 times and it only once did bubble all those variables to the parent scope. difference was that in the other two service task definition i had defined output variables and only those output variables i defined were bubled to the parent scope.

so turns out it already behaves the way i expect, just only when defining the output variable

this also was mentioned in the documentation you linked

If one or more output mappings are defined, the job/message variables are set as local variables in the scope where the mapping is defined. Then, the output mappings are applied to the variables and create new variables in this scope. The new variables are merged into the parent scope. If there is no mapping for a job/message variable, the variable is not merged.

If no output mappings are defined, all job/message variables are merged into the process instance.

so as usuall pebkac, thanks for rubberducking :slight_smile:

1 Like