But for some reason this doesnt work, (It does work when ran manually so it must have to do with the fact that it’s not an ID but a string)
Does anyone know how to fix it or what’s wrong with the code? (This code does work with ID’s)
Without having looked at the code at all. Did you check it in production mode? Because running a workflow manually (when pressing “Execute Workflow”) does not save static data.
It looks like you are using the data from “status” which contains strings like “open”. That would not work as multiple rows would have similar data. You would have to use a unique value like an ID or a date-time for it to work.
I would store both the ID and status in an object. On every execution, I would then check for the status of an ID and if it got changed I would return it. I hope this helps.
Hey @Damian_K! I took a quick look, couldn’t dive into it, and found out that your code isn’t comparing the status correctly. Let me try to explain the idea I had to solve this issue.
On every execution, we store the incoming data in an array. This array should contain objects with id and status. Our static data should also contain the data in a similar format. [{id:1, status:'open'}, {id:2, status:'close'}] something similar to this. We then check the status for each ID. If the status changes we return the new status or do nothing. Your code is not storing the data in the correct format, and not filtering it as needed. I hope this helps.
I tried debugging your code. For me, the oldStatusIds is not getting updated with the newly modified data. That can be a reason that we are getting the desired output. I log the variables on the console to debug and understand the structure that they store. I did the same for your code and the structure is different from what we need. For example, newStatusIds only stores the status and doesn’t store the IDs. Is that intentional?
Another structure we can use is as follow { 1: 'Open', 2:'Close', ...}. Here, 1, 2 are the IDs and we are directly mapping the status to the IDs. Let me know if this makes sense.
Hey @harshil1712 I looked at the workflow you posted at https://n8n.io/workflows/864
if this indeed watches changes in the data, would this work for me perhaps?