Add if/else data to Data Table outside the loop

Hi guys!

I’m getting multiple data elements (Company Id, Status, Date, Previous Operating Name etc) from a website and storing it in a variable. However, I’m doing this in different if/else loops. For ex: Company Id and Status in first loop and Date and Previous Operating Name in the second loop. I am using Build Data Table and Add Data Row to store the data. But since I’m using Add Data Row outside the loops (scope), it is throwing an error.

How can I collate and add all of these data to a data table in a single row outside the loops?

The output should be in this order -
Company ID | Status | Date | Previous Operating Name

First save the values one by one with a list variable using ADD TO COLLECTIONS activity

and pass that list variable to add Datarow activity under the property Array- item as listvariable.ToArray()

Then use assign activity and pass the same above created list variable and mention like this
Listvariable = nothing
This is to be done to remove all the available values and take new values in next loop

Keep all this insideloop so that every time it appends each value to the loop and that list variable will be passed as array to add Datarow
Then list will be cleared and again used to save new values

Cheers @HS_Manohar

1 Like

Hi @HS_Manohar ,

To achieve this

Before moving forward create two data table variables dt1 and dt2
Create Counter variable As Counter(of integer) = 1

1 - Create all column in build data table and store it in dt1 (Also add one Id column)
2 - Use assign activity
dt2 = dt1.Clone
3 - Use first loop and add data to dt1 with the help of Add Data Row activity (pass counter in column id )
Note : In loop you have to increase counter and reinitialize 1 when new loop started
4 - Use second loop and add data to dt2 with the help of Add Data Row activity
5 - Use Join activity to join both dt and select respective columns for result.

Let me know if you face difficulty to achieve this.


1 Like

Hi @HS_Manohar
First main aim to get the data, so first create a variable of datatype,String[string].

Then each of its element should be of like this

{{Company Id, Status, Date, Previous Operating Name},…}

Now loop through that variable (for each item in variable)

Then inside it use add datarow , To add each array element to datatable

Hope it helps

Nived N

1 Like

Thank you all for taking your time to answer my question. I changed the scope of all the variables to global so that I could access them outside the loop and used Add Data Row activity to add them to the data table.

1 Like

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