I am building a custom node. To make the automation seamless, I want to pass a part of the payload that I receive from my previous node. However, when using the expression in the input field, it resolves the expression. As a result, always the value is returned.
Eg.
Payload from previous node:
{
...,
displayName: 'Name'
}
When I use the expression, {{ $json.displayName }} in the input field of my custom node, it returns Name. What I would like to have is something like {displayName: Name}. What would be the best way to implement that in my custom node?
Hey @harshil1712,
expressions like {{ $json.displayName }} will only resolve the value but they won’t give you the key name. To set the key name you would need an additional string parameter. You could put both key/value parameters inside of a fixedCollection, like for example our Edit Fields (Set) node is doing here. The requiresDataPath: 'single' property tells n8n to insert the key name (instead of an expression) when using drag/drop to map input fields.
Thanks @marcus. This helped. I am interested in getting the last key in the chain, eg: if the expression looks like {{ $json.body.displayName }}, I would like to get displayName. requiresDataPath gives the whole path.
For now, I am handling this programatically, but is there an option that already takes care of this?
Also, out of curiosity, what is the difference between requiresDataPath: 'single' and requiresDataPath: 'multiple'?
No there is no option to handle this automatically since most of the time we are interested in the full path.
When drag/drop multiple fields in the same node parameter n8n will either replace any existing value (single) or concatinate (multiple) ones comma separated.