Reputation: 361
I'm encountering an issue with a Directus Flow where my plain, nullable full_slug
field is being set to undefined
in the Update Data stage, despite being correctly defined after the Custom Script execution.
The flow consists of the following stages:
pages.items.update
)Here's the Custom Script that correctly updates the full_slug:
module.exports = async function(data) {
const slug = data.$trigger.payload.slug;
const parentItem = data.item_read_lhmzf;
const currentItem = data.item_read_mn69m;
if (parentItem && parentItem.full_slug) {
data.$trigger.payload.full_slug = parentItem.full_slug + '/' + slug;
} else if (currentItem && currentItem.full_slug) {
const parts = currentItem.full_slug.split('/');
parts[parts.length - 1] = slug;
data.$trigger.payload.full_slug = parts.join('/');
} else {
data.$trigger.payload.full_slug = slug;
}
return data;
}
Event payload slug: rabbit-facts
Parent item full_slug: home/blog
Current item full_slug: home/blog/rabbit-factoid
After the Custom Script execution, full_slug is correctly set to home/blog/rabbit-facts
.
At the Update Data stage, the ID is set to:
{{$trigger.keys[0]}}
…which seems to be correct.
And the payload is:
{
"full_slug": "{{$trigger.payload.full_slug}}"
}
However, the final output in the Update Data stage shows:
{
"collection": "pages",
"payload": {
"full_slug": "undefined"
},
"key": [
"b7034f18-8079-43aa-a448-5c3d45c71cbe"
]
}
Any insights would be greatly appreciated. Thanks in advance for your help!
Upvotes: 1
Views: 124