How to check if imported CSV file contains rows of data?

Hi,

I have an Import CSV server action which I need to check if its empty.

image

How do I return an error if the file only contains headers and no row data?
image

I tried the following, image and image

image

Thanks,
Ray.

I wouldn’t have thought it would be possible to determine if a single row of data is a header or actual data. If you know the file will contain a header, you could test for a single row being imported.

Hi @TomD,

The you can tell the Import that your file contains headers, so I would have thought I could check for rows.

image

Ray

Why not use your database query for results?
If it returns > 0 records then do the export.

Hi @Teodor,

This is an “Import CSV file” action I am performing.

I need to ensure the user has not just uploaded a file only containing the header, and if they did, I will return an error onscreen.

It would be great if we could do some validation on the “Import CSV file” out of the box.

But on import headers are not considered a record…

You can set a condition which checks if the imported file returns has records or not:

1 Like

Thanks @Teodor. I was trying to check for null, but now I can see that a zero count would have worked for me.

Hi @Teodor is it also possible to check for duplicate values on the Import?

e.g. Check if a column on the CSV file contains the same value twice and if it does return a response?
image

I need to raise an error if the Column A(Proxy) value has been entered twice. I need to do this before I commit to the database.

You can check the value using a database query - use the csv column as a query filter.
Add a condition which checks if the database query returns a record and add your steps there.

Hi Teodor, I need to preform the check on the import file to ensure that it does not have it duplicated. In the previous post you will see Row 2 and 3 have the same value under column 1.

What I don’t want to do is import the data into the database if the value exists more than once in the file.

If it needs to be done a DB level, that won’t catch if the value has been duplicated in the file, it will only tell me if already exists on the DB?

Yes, but if it doesn't exist in the db, and it exists twice in your CSV, then it will be added the first time when you do the insert, then it won't be added the second time as it already exists ... :slight_smile:

I understand what your saying, however, then I won’t be able to warn the user that they have entered the value more then once and I could have committed most of the file to the DB?

So what’s your idea exactly?
Isn’t it - not to enter duplicate records in the database? Or is it something else?

I want the user to be warned that they have added a duplicated value, which could have been a simply typo on their part, and that they need to correct the file and re-upload after fixing the file by either fixing the value or removing the line completely.

If I go by the example below.
image
Ray and James are both to receive a value, but the user added the same Proxy to both users. If I simply removed the duplicate, then James will not receive a value at all.

By highlighting to the user that they have duplicated the Proxy value, they can amend the Proxy to the correct value and then resubmit.

And do you want to check this for a specific column? Or all columns?

Just a specific column.

Well in this case you can check if the number of unique records are equal to the number of total records :slight_smile:

you can build pretty much everything you need to check/compare using the data formatter.

1 Like

Didn’t catch the duplicate?

image
image

Now, I did type in Proxy into the Property Field.
If I try using the picker I get the following, which also does not catch the duplicate, but I’m sure thats because it’s only getting the first row [0]

image

1 Like

How about having a separate table called ‘duplicates’ and insert records in there if they appear more than once? Then you can report back exactly which records were duplicates.

1 Like

Your condition is wrong on your screenshot…
If unique items count == total items count, then there are no duplicates :slight_smile:

You need to put the response in the other step (else).

1 Like