Flow blocking: Read Data returns FORBIDDEN when checking duplicate courses

I am trying to create a Flow to prevent duplicate entries in the “cours” table.

Fields in “cours”:

  • Ense
  • activite
  • date_cours

The Flow is of type “Filter (Blocking)”. The Read Data node filter is:

{
  "_and": [
    {
      "Ense": {
        "_eq": "{{ $trigger.payload.Ense }}"
      }
    },
    {
      "activite": {
        "_eq": "{{ $trigger.payload.activite }}"
      }
    },
    {
      "date_cours": {
        "_eq": "{{ $trigger.payload.date_cours }}"
      }
    }
  ]
}

Even when no duplicate exists, I get this error:
“[FORBIDDEN] You don’t have permission to access this.”

The forbidden error is returned when you're either reading from a field you don't have permission to, or a field that doesn't exist. Are you sure those 3 field names are correct? They are case sensitive so Ense (Capitalized) and activite (lowercase) is a bit suspicious to. If those are confirmed, make sure that those fields are accessible to the operation in the flow

2 Answers

2

hi and thanks a lot for your reply
I created a flow to control duplicate records, and I implemented the following configuration:

1. Read Data Operation:

{
    "filter": {
        "_and": [
            { "Ense": { "_eq": "{{ $trigger.payload.Ense }}" } },
            { "activite": { "_eq": "{{ $trigger.payload.activite }}" } },
            { "date_cours": { "_eq": "{{ $trigger.payload.date_cours }}" } }
        ]
    }
}

2. Add Script Operation:

module.exports = async function(data) {
    return (data.read_data.length > 0);
}

This script returns true if a duplicate exists.

3. Condition Operation:

{
    "check_dup": {
        "_eq": true
    }
}

The issue:

Even when there is no duplicate, Directus still returns this error:

The following fields contain invalid values:
check_dup: The value must be true

It seems that Directus is requiring the value true even when the condition should evaluate to false (i.e., no duplicates found).
nb:can i add a node “create data” if record is no duplicated??

I've followed up on one of the duplicates you created https://community.directus.com/t/flow-to-control-duplicate-records/1529 Please don't open any more duplicates for this same one. I know it feels like it makes your question more visible, but in reality it makes it a lot harder to keep track of the answer and might even get you flagged as spam. Thanks!

ok my brather thanks