Hi all,
I trying to compare 2 CSV file and have an output in a 3rd CSV with all the relevant information.
However the data after reconciliation only show the ‘Country’ row.
How do i populate all the other rows as well?
The Output DT needs to be defined if you are adding rows to it. i.e., the column names and the order of the addition of column values need to match.
We can keep the if logic simple (easy to comprehend) by using the Index variable which is auto incremented in a For Each Row activity. This allows us to use the
DT.Rows( <row number> ).Item(" <Column Name> ").ToString
In your case the if condition can be simplified: row("Country").ToString.Trim = dtBook1.Rows(Index).Item("Country").ToString.Trim
When adding rows to a table, the length of the array should be the same as the number of columns in the Output DT.
Here is the required output you are looking for (Output.csv). You have to change the input and output csv file paths to reflect your required file paths. Currently, it uses dummy csv’s.
I have also added a negative test case to test the workflow.
Alternative (a better solution):
To use the Join Datatable activity to achive the same. It is much more elegant solution. All conditions would be specified within it and the workflow will be easier to read.
Why is it not working?
It wont work because in the initial question you have the Country Table as first input table and the solution uses that as to be checked table i.e., only check as far as the Country table length. So when the tables are interchanged the logic of a join will be different. Simple solution is to reverse the order of the table and keep all other things constant and it will work.
Both solutions will work provided we input the correct table to get in the For Each Row and values in the Add Data Row activity.
Solution to the new test data
I would advice you to go through both solutions to figure out the changes. I have updated some annotations. Here is the updated workflow with your new data and table order. Update-SolutionComparetwoCSV.zip (2.7 KB)
Two tips for you:
Write the test data in csv or attach excel file in forums. Much faster to answer question which also provide the data in a easy to copy format
Work hard on understanding Datatable manipulations, it is a steep learning curve, but once you get hang of it, any automation project becomes fun. Just take any datatable and use all possible Datatable Activities to learn them.
That is true it will show that error if the tables are ordered different and also depending on the row length. It will work but you could use the alternative solution.
Alternative (a better solution):
I am attaching the better solution, which I mentioned ealier in this thread i.e, Inner Join of Datatables. This is not dependent on the length of rows, you will always get the correct output and the workflow is easy to read and no need to manipulate rows. Annotations are in the file as well.