Modifying JSON variable

Hi All,

Am new to Flowable engine, please bear with me if my question is amateur.

So I know we can start a process instance by passing json variables.
For example, consider this json
{
“name”: “payload”,
“type”: “json”,
“value”: {
“addonId”: 465,
“action”: “Remove”
}
}

In a particular scenario, I wanted to update the existing field in the json variable from the flow using a execution listener which has the following expression

${execution.setVariable('${payload.action}', 'Add')}

I see that the json variable gets modified but not persisted, because I can’t see the modified value once the transaction is committed (either because of a async service task or timer event).

I did some debugging and saw when the variable is modified using the execution listener, its getting set in the cachedValue but not in the textValue of VariableInstanceEntity and is not getting persisted.

But the above method worked when I set a new field inside the same json.

For example this expression persisted the serviceId field inside the json and was available for the subsequent flows.

${execution.setVariable('${payload.serviceId}', '123456')}

I can look for workarounds, but I just wanted know whether this behavior is on purpose or any particular reason.

Thanks

1 Like

Hey @rjrobinjoshua,

Your question is far from amateur. Seems like you know what you are doing and you have analysed your problem quite good :wink:.

The problem you are seeing (the json variable being modified, but not persisted) has been fixed on master. This has been done in this commit and improved in this commit.

Currently, what you can do is to explicitly set the payload in the execution, after you do the updates to the payload (e.g. ${execution.setVariable('payload', payload)), this would trigger the update and make sure the new value of the variable would be persisted.

Cheers,
Filip

1 Like

Hi @filiphr ,

Thank you for the prompt response.
Great to hear that this is fixed already :slight_smile:

Will pull the latest code from master.

Cheers,
Robin