Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Hurra on November 16, 2023, 08:59:42 pm
-
Hello!
(using JScript)
I initialize CSV-import:
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:
function OnRowImported()
{
if (!checkForColumns(columns))
{
log(true, "Column not found, stopping script...");
return;
}
...
where checkForColumns() uses CSVIContainsColumn() from EAScriptLib.JScript-CSV:
...
if (CSVIContainsColumn(column) == false)
...
However, CSVIContainsColumn(column) always returns false for the first column.
Example CSV:
first;second;
1;2;
a;b;
I define my variable columns as
columns = ['first', 'second'];
The function from EAScriptLib.JScript-CSV returns false:
CSVIContainsColumn('first') -> false
If I however add a dummy column in the beginning, like:
zero;first;second;
;1;2;
;a;b;
then
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:
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