Adding data to a datatable in a specific column

Hello all,
My proccess is

  1. reading the data from a txt file, read CSV
  2. converting it to a data table,
  3. Adding a new column to that datatable in the form of (Y/N), Add data column
  4. Using for each row i then assign Lists for each column
  5. Then Add to collection for each of the list created
  6. Then use For Each (Item in col1List)
  7. Then an if statement with condition col2List(0) = “2”

And here is my question.
when the statement is true i am wanting to write “Yes” in the column i have created and when false “No” given that specific record. It is not working with the current method is have and was hopping to get a solution to this problem as i can not find any resources on this.

Here is my for Each Body so far:

Thank you


Instead of updating in the list, you need to do it in the row directly.

row(“yournewcolumn”) = “Y”

i have a small doubt here
in for each we have mentioned as col1List
and in the IF condition we have mentioned as col2List
and inside the THEN and ELSE part we have y_nolist

may i know where these list variables are used as you said you have only one list variable
Cheers @Rowley101

like this?

(Y/N) is the name of that column

colList1 is used primary key
colist2 is the values of the column in the list
y_nolist is the list of initially null values from the column i have created using add data column

@Rowley101 If I understand it correctly, you are looping through a datatable and inside which you are checking a list for values.
First question what this list contains?
Secondly, You are looping through colList1 and checking the condition in colList2. what is the relationship between these two lists
Is it possible to share the workflow with annotations.

Yes, like that only

does not work my friend

can i have your workflow if possible
Cheers @Rowley101

Main.xaml (23.3 KB)


my test file. needs to be writen in notepad

I have updated your file. Please try it now and see.
Main.xaml (15.4 KB)

Thank you my friend for the solution.
I have solved it i different way to that if you care to take a look ReadAndWriteIntoTextFile.xaml (21.3 KB)

Hello @Rowley101,

You can use add data row to add a row of data to your columns all you need to do is fill the input were datatable is the datatable you want to add info to and array row the array of info you’re adding. For example: {variable1,variable2}. Variable1 will be assign to the first column and variable2 to the second column. As well you can put there for example a string, just remember that the info must be of the same type as your column type. sample: {“yes”, variable1} you this activity in the if true and if yes and add the different values. if true then {“yes”, variable1} else {“No”,variable1}.

@Rowley101 Output wise your approach will work as you are expecting. But as per standards and process improvisation, below are some of the points that i would like to highlight-

  1. Multiple loops - You have declared two for loops. One for data table (Loop1) and other for list collection (Loop2). You are instantiating the list every time you fall into the Loop1 and adding the column value into the collection. This means, for every row there will be only one item in each of the list collections. Hence Loop2 is not required here. Even you are looping through Loop2 but not utilizing the loop value. i.e., item. Instead directly accessing loop for the 0th item.
  2. List collections - You are instantiating list collections for every row item which comes with the cost of memory and space. Additionally, the you are assigning values from row to list collection but some of these collections are not used anywhere in your workflow. The one list collection you are using is to check the value, which can be achieved by directly checking the column value in the row as well. This will reduce lines of code as well as processing time.
  3. Accessing Columns - You have used column indexes to access the columns. But in real scenarios sometime the columns might not be in the same order that you are expecting. Hence its preferred to refer column names instead of column indexes.

Hope this will help you!

I am fairly new to RPA and currently doing my first project at work on it so the more i know the better.
That was mainly a scenario as i am currently working on a process much bigger at work.
as for the points:

  1. I have Amended the double loop and just put it within a single one, i.e. the for each row
  2. i have, in the robot i am working on at work needs all lists collections instantiating so it was more of a practice thing.
  3. The data i will be receiving will remain in the same format everytime so i have no need to change the indexes.

Thank you for your help and comment @Madhavi

Welcome to RPA @Rowley101
Don’t worry, you will learn it in no time. All the best.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.