splitCSVRecord() will split the single line text into a single level list. Since his list contains multiple lines, I have to split first using split(csv, "\\r?\\n"), then splitCSVRecord() upon the loop, and add it to the new Map. \\r? part is to handle windows' newline break.
However as I tested, the result of the split is always a nested list, not single level. This throw me an error when referring to the second element. So instead of
[1,Aneka Abadi,123456,Jalan Bakung no 12,A]
I got it nested
[[1,Aneka Abadi,123456,Jalan Bakung no 12,A]]
If I dig down the list using debug dialog, I can see the list is stored in nested list clearly. So I wonder what is the difference.
I copied the csv raw data and tried to replicate it in other script element. I got the result correct, it is single level list. Then I repeat the same at the main flow, still got nested list. I tried split(j, ",") to split it manually using comma, I got the result correct, single level list. So what the heck happened, why I can't use the usual splitCSV here?
I am drowsy and fell into sleep. After wake up several hours later, my mind still directed to this. I then mirrored my phone to PC and pay attention properly to see what is the real difference. Finally I saw it!!! The splitCSVRecords() in the main flow have extra "s". While the one in my test script and other flows I usually use, don't have extra "s". So it is splitCSVRecords() vs splitCSVRecord(). It seems I type the script manually in main script and use function button in test script. As in the function button, the only available is the one without extra "s". This explain why I got single vs nested.
In summary
splitCSVRecord() = split single lines of csv into single level list
splitCSVRecords() = split multiple lines of csv into nested level list.
This is such as breakthru, that my 2 years+ with automagic seems like a lie. Taking the example from other thread, I used to use something like this.
Code: Select all
csv = '"Hope, AR, USA",33.669964,-93.590096\n' +
'"Tujunga, Los Angeles, CA, USA",34.263302,-118.302711\n'+
'"Bonnybridge, Scotland, UK",56.003227,-3.888634\n' +
'"Tarzana, Los Angeles, CA, USA",34.150879,-118.551651' ;
temp = split(csv, "\n");
database = newList();
for(i in temp)
addElement(database, splitCSVRecord(i));
Now with the splitCSVRecords(), I can do it in one line script.
Code: Select all
csv = '"Hope, AR, USA",33.669964,-93.590096\n' +
'"Tujunga, Los Angeles, CA, USA",34.263302,-118.302711\n'+
'"Bonnybridge, Scotland, UK",56.003227,-3.888634\n' +
'"Tarzana, Los Angeles, CA, USA",34.150879,-118.551651' ;
database = splitCSVRecords(csv);
Now I am going to slim down some of my flows which use the splitCSVRecord(), to make it shorter and more efficient.
@Martin : I think we should have the splitCSVRecord() and splitCSVRecords() mentioned both in the function button.