9
Views
3
Comments
Solved
Validation for CSV file template

Is there a way that I can validate a csv file header?

I have an import action that must always receive a file that has the following header: Code, Name,Number at the correct order and correct header.

How I can I do a validation to know if the imported csv file has the correct header/template?

Backoffice.oml

Rank: #55
Solution

Hi Marco,


You can make use of BinaryDataToText action from BinaryData extension:


It will convert the binary data to text and then you can see if it starts with Code;Name;Number. Check the debug screenshot from the output of the BinaryDataToText action of a sample CSV:


Your condition could be something like this:

If(Length(BinaryDataToText.Text) >= 16,
    Substr(BinaryDataToText.Text, 0, 16) = "Code;Name;Number",
    False
)


Hope it helps.


Regards,
João

Rank: #9079

Hi João

For an aditional validation would there a way to validate if the file has aditional columns. I beside these three that are already in the example, if the file had more columns how could avoid that? Thanks

Rank: #55

Hi Marco, 


Having never tried that, I'd say you need to check that there is a new line after the three columns. I never tried to do that with substr function but with regex this validation is certainly doable.