Allow duplicate if condition is met

Hi everyone,

I am wondering if it is possible to create a query that will look into my field "BarCode" if the record exist, then it will look if the field "DeliveryDate" is null.
If it is null, It needs to stop the user from creating a duplicate entry.
If it is not null, it must allow the user to create a duplicate entry.

Ex
BarCode / DeliveryDate
12345 / 2024-09-09
67890 / null

the user would be able to create a new entry for 12345 but not for 67890

Not sure if I am making sense :thinking:

Thank you for your help !

Hi @brocantcode, we would have to run two queries to achieve this. The first query would pull all records that match the 'BarCode' the user is trying to create an entry for. We can attach a success event handler to this query, where we iterate over the response and see if any of the results have a value of null for the 'DeliveryDate'. If we find a value of null, we just raise an error to notify the user. Otherwise, we trigger the query to create the new record.

Hi thanks for the reply ! I was on vacation for a month and could not try this before.
Not sure how I can iterate over the responseto another query

I tried to look at the lenght of the array using the only run when, but the length is always 1.
image
image

The .dataArray property includes the column names:

Try formatting your data as an array (check 'Transform results' above) and referencing DoublonVerif.data.length instead.

1 Like

Working perfectly !
Thank you so much for your help !

If I may ask for alittle more, is it possible to throw an error when the only run condition is not met ?

1 Like

You are welcome! :slightly_smiling_face:

Not directly but we can build this in a slightly different way. Instead of triggering the query directly (i.e. submitting a form, clicking a button), we can run a script that triggers the query or shows the error depending on that condition:

If the condition is not met:

Here's our doc on this util function:

1 Like