Flow (for creating slug) not working - "You don't have permission to access this"

I have a Flow works fine when it comes to creating or updating a slug. It is what was shown here on Directus a year ago (or maybe even longer, when Flows became popular).

But that flow only receives the payload from the very field that was changed. Nothing else. So it needed to be a change in the “title” field in order to make the slug action work.

I, however, need to combine field in order to achieve the requirement of having a unique slug. Since the collection is one, where the titles will very often be just something like “Concert”, that uniquness is not given. I therefore want to use the date_created and the id field like this:

slug: {{ title }}-{{ date_created }}-{{ id }}

In order to do so I added a “Read Data” operator (? is that how those items are called?) to the flow, right after the “Trigger” and before the “Run Script” operators. I keep using {{ $trigger.collection }} and {{ $trigger.keys }} to get the proper item from the collection. I was hoping that that allows to access the whole collection in the “Run Script” operator, where I have this script:

```js

module.exports = async function (data) {
// Get the complete item from the “Read Data” operation
const item = data.$trigger.operation[‘read-data’].result[0]; // [0] because it’s an array

// Extract fields you need
const title = item.title || ‘’;
const dateCreated = item.date_created ? new Date(item.date_created).toISOString().split(‘T’)[0] : ‘’;

// Generate slug using both fields
const text = ${title}-${dateCreated}-{$item.id};

const slug = text
.normalize(‘NFD’)
.replace(/[\u0300-\u036f]/g, ‘’)
.toLowerCase()
.trim()
.replace(/[^\w\s-]/g, ‘’)
.replace(/[_-]+/g, ‘-’)
.replace(/^-+|-+$/g, ‘’);

return slug;
};

```

The final “Update Data” operator, again using {{ $trigger.collection }} and {{ $trigger.keys }}, uses this json in its Query field:

```json

{
“slug”: “{{ slugify_data }}”
}
```

However, renaming the title of an event only ever gives me an error, and if I am not mistaken, that already happens in the Read Data operator:


Read all data from Events collection Read Data

Options


Payload


{ “name”: “DirectusError”, “message”: “You don’t have permission to access this.” }

Here are some screenshots about my flow. Can anybody help me out figuring out what I have to do to make this work, please?