I’m struggling with understanding the syntax for handling data returned by the Compare Datasets note in a code node. I want to set a value based on if the field in question comes through the ‘A only’, ‘B only’, ‘Same’ or ‘Different’ path. The idea is that if the value is in the ‘different’ array/object, use the value from the most recently-modified input, and if not, use the same value if that isn’t undefined, and otherwise default to the value from a previous ‘Set’ node.
The current error message: Problem in node ‘Get process name‘
Cannot read properties of undefined (reading ‘process’) [line 4] TypeError
Here are the two relevant nodes. The Compare Datasets node has an Input A and an Input B, both with a field called ‘process.’
and the JavaScript code:
let process;
// Check to see if the process value is in the different branch. If so, compare timestamps and take the process value from the latest
if (typeof $node["Compare Datasets"].json.different.process !== 'undefined') {
process = $node["Input A"].json.lastModified > $node["Input B"].json.lastModified ? $node["Compare Datasets"].json.different.process.inputA : $node["Compare Datasets"].json.different.process.inputB;
}
// If not, check to see if the process value is in the same branch. If so, use that value
else if (typeof $node["Compare Datasets"].json.same.process !== 'undefined') {
process = $node["Compare Datasets"].json.same.process;
}
// If not, use the value from Input B (MySQL)
else {
process = $node["Input B"].json.process;
}
return process;
Information on your n8n setup
- n8n version: 0.221.2
- Database (default: SQLite): SQLite
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app): cloud
- Operating system: