I am comparing data from a set of reference fields to those that actual users have. If the user has the data, the value is updated and I then ‘push’ the values into a new item in my json object. I have found that for some reason all users get the value of whatever the last user is that has been added.
I have done the following:
Made sure the temp object that I push to the ‘main’ object is cleared on each iteration of the loop
Checked the values of all objects at each step to make sure they are correct (via console)
Tried both ‘push’ and ‘concat’
It seems the problem lies in the push/concat step.
Here is an example of the output data I get. The “value” for the “customFields” on “billy bob” should be blank, but it assuming the value from “amy jones”.
It looks like something went wrong the json you pasted for your workflow, Can you edit your message and paste the workflow json between 2 sets of ``` this will then show the workflow preview and will allow us to see what is going on.
Just fixed it. After doing some research, I think the issue is with how I’m making my temp object copies. I think I need to be doing something like newArr = […origArr], but this is new to me.
The issue was that I was doing a shallow copy of my objects and arrays for temp use in loops. This was in turn causing the values to pass through to the original each time I wrote to the temp objects, thus resulting in the value of the last contact being used for everyone.
The solution was liberal application of newObj = JSON.parse(JSON.stringify(origObj))
I am a big fan of just get it done and improve it later here is a little tweet I posted a while back about a workflow I have that I improved that sort of shows how messy I can be with a first version: https://twitter.com/JoffCom/status/1601554022615642113