Hello folks,
The function below was working normally, but after some n8n updates it stopped working as it should.
What it does is get a value from a previous node and check if this value is the same, if so it should return the string “Mesmo Motorista” but it is not returning that value anymore. It keeps returning the same value in an array.
Nothing has changed in this function.
const new_items = [];
// Get static data stored with the workflow
const data = this.getWorkflowStaticData("node");
data.placaatual = data.placaatual || [];
for (var i = items.length - 1; i >= 0; i--) {
// Check if data is already present
if (data.placaatual.includes(items[i].json.placaatual)) {
break;
} else {
// if new data then add it to an array
new_items.push({
json: {
placaatual: items[i].json.placaatual,
},
});
}
}
data.placaatual = items.map((item) => item.json.placaatual);
// Check if array is empty
if (new_items.length === 0) {
return [{ json: { placaatual: "Mesmo Motorista" } }];
} else {
// return new items if array is not empty
console.log(new_items);
return new_items;
}