I’ve created a workflow that creates a folder and a list in Clickup, then gets all tasks from a “template” list and creates new tasks in the freshly created list based on the template tasks (because there’s no API endpoint for using a list template). This works fine when I hardcode the list ID in the task creation node, but if I refer to the list with {{ $node['post-list'].json.id }}, it shows up correctly in the UI but on execution only one task is created and then I get an error “List ID invalid”.
Am I correct in assuming the list ID should be available during the entire loop, not just the first item?
Based on your description I suspect the number of items you’re processing could change between your nodes. This is likely to cause the problem when using an expression of {{ $node['post-list'].json.id }}:
For the first item your node receives, this expression would read the id value from the first item on the post-list node which is fine. For the second item it would read the id value from the second item on the post-list node and so on.
Now if your post-list node has only one item, there would be no value for all subsequent items on your current node. This means n8n would send an empty value to Clickup, and thus causing an error.
In such cases you can use an expression of {{ $('post-list').first.json.id }} to always read the first item from your post-list node. If your post-list node would have multiple items, you could try using {{ $('post-list').item.json.id }} instead which makes use of item linking to identify the correct corresponding item.
I actually thought of this, and tried using first(), but the editor doesn’t let me use first() since the node doesn’t return multiple items, therefore $('post-list') isn’t an array. $('post-list').first doesn’t exist.
Is there a way to set the value of $('post-list').json.id to a workflow context variable, which could be then injected to each item after the get-tasks-template node with the “set” node? Or can I use some other reference to explicitly force the item loop to refer to a single value on each iteration?
@MutedJam, that worked! I actually confused $('nodeName') and $node['nodeName'] syntaxes, and only the first returns single items as array, the second ones throws an error first() is only callable on type "Array".
This resolves my issue, thank you for the great support!