Problem with custom node Execution Data

Hi,
I have a problem with execution data, consider this workflow:

Trigger Node ---------> Node 2 [ item.json[‘testVariable’] = 1 ] ---------> Node 3 [ item.json[‘testVariable’] = 100 ]

After the execution is done in the execution detail we can see items as below (table or json view):

Trigger node [ related trigger data ] --------> Node 2 [ “testVariable”: “1” ] ---------> Node 3 [ “testVariable”: “100” ]

Everything is working fine so far. But things getting strange when I use my custom nodes. Consider that exact same workflow above, after the execution is done what we see in execution detail is:

Trigger node [ related trigger data + “testVariable”: “100” ] --------> Node 2 [ “testVariable”: “100” ] ---------> Node 3 [ “testVariable”: “100” ]

As you can testVariable is passed to previous nodes as well (such as trigger node!) and also the last value overrides all the previous data with the same variable name.

What is happening here? Do you have any idea what cause this problem?
Thanks

I assume you are changing the incoming data in your custom node which is not allowed and which will mess up stuff very badly. The reason is that data is passed around as reference.
You can find it in the guide here.

1 Like

Thanks @jan for the answer.
So if that’s the case I have to change “item.json[‘testVariable’] = 1” to something dynamic. I mean ‘testVariable’ must generate dynamically. Am I right?

You really would have to copy the data.

For example something like this:

let newItem: INodeExecutionData;
...
newItem = {
  json: JSON.parse(JSON.stringify(item.json)),
};
returnData.push(newItem);

You can find an example here:

1 Like

Thanks @jan . It works perfectly:

let newItem: INodeExecutionData;

newItem = {
    json: JSON.parse(JSON.stringify(item.json)),
};

newItem.json['myVariable'] = Date.now();
returnData.push(newItem);

And in duplicated nodes I see different timestamps.

Thanks again.

Great to hear that it was helpful! Have fun!

1 Like