Author Topic: CSV import doesn't find first column the first time?  (Read 2318 times)

Hurra

  • EA User
  • **
  • Posts: 183
  • Karma: +0/-0
    • View Profile
    • Find me at LinkedIn!
CSV import doesn't find first column the first time?
« on: November 16, 2023, 08:59:42 pm »
Hello!

(using JScript)

I initialize CSV-import:

Code: [Select]
    try
    {
        CSVIImportFile(fileName, firstRowContainsHeadings); // See EAScriptLib.JScript-CSV
    }
    catch (error)
    {
        log(true, "Error importing CSV file. Is the path correct? Is the file open?");
        log(true, "Stopping script...");
        log(true, "====================END====================");
        return;
    }

Then in OnRowImported() I check for my defined columns:
Code: [Select]
function OnRowImported()
{
if (!checkForColumns(columns))
{
log(true, "Column not found, stopping script...");
return;
}
...

where checkForColumns() uses CSVIContainsColumn() from EAScriptLib.JScript-CSV:
Code: [Select]
...
if (CSVIContainsColumn(column) == false)
...

However, CSVIContainsColumn(column) always returns false for the first column.

Example CSV:
Code: [Select]
first;second;
1;2;
a;b;

I define my variable columns as
Code: [Select]
columns = ['first', 'second'];
The function from EAScriptLib.JScript-CSV returns false:
Code: [Select]
CSVIContainsColumn('first') -> false

If I however add a dummy column in the beginning, like:
Code: [Select]
zero;first;second;
;1;2;
;a;b;

then
Code: [Select]
CSVIContainsColumn('first') -> true

Later, after importing and creating elements, I add the GUIDs of said elements back to the CSV.

But I discard the dummy-column, so after import and export the CSV looks like this:
Code: [Select]
first;second;guid;
1;2;guid1;
a;b;guid2;

Then all of a sudden CSVIContainsColumn('first') -> true without the dummy column...

I have no idea what's going on and don't know how to troubleshoot this. Hopefully someone can follow my explanation.

Can it have anything to do with different types of CSV's? In Excel there are options for (at least for me):
  • CSV-UTF-8
  • CSV
  • CSV (Macintosh)
  • CSV (MS-DOS)

Is there a known bug using EAScriptLib.JScript-CSV and specifically CSVIContainsColumn()?

Any help or pointers appreciated! Thanks!

I'm on version 16.0.1604
always learning!