Geeta
(Geeta)
June 30, 2023, 8:42am
1
Hii,
Im using two for each loop activities, where in
First for each loop DTrow has values 1,2,3
And inside that I’m using another for each loop DT2 which has values 18,19,20
So when the bot iterates through first DT it takes first item : 1
And moves to DT 2 and takes : 18
And second iteration, it takes 19, but the first DT is : 1 only.
I want the bot to take the values simultaneously like:
From first DT if it is 1 and DT2 18, 2 and 19, 3 and 20 like this.
How do i do this?
ppr
(Peter Preuss)
June 30, 2023, 8:59am
2
Assumption: both datatable do have the same row count
We can do it by
For each row in Datatable Activity: row in dt1 - Index output: idx
Assign Activity: d1Value = row(ColumnNameOrIndex).toString
Assign Activity: d2Value = dt2.Rows(idx)(ColumnNameOrIndex).toString
OR
we can use a LINQ
[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum
Anil_G
(Anil Gorthi)
June 30, 2023, 8:59am
3
@Geeta
You can use for each row in datatable on dt1
and use a variable for index property in for each row activity and use that index to get data from second table for same index like currentrow("Col").ToString
gives data from table 1 which is dt1 and for dt2 use dt2.Row(varindex)("Col").ToString
Hope this helps
cheers
Geeta
(Geeta)
June 30, 2023, 9:17am
4
Hi @ppr
Can you write a workflow using 2 for each loops and share
ppr
(Peter Preuss)
June 30, 2023, 9:20am
5
with this input
we are confused by
Geeta:
using 2 for each loops
as we saw the request, that 2 loops are to avoid.
Maybe you can elaborate more on this or present more the use case on which you are working on
Geeta
(Geeta)
June 30, 2023, 9:25am
6
I have one datarow values are 1,2,3
And another datatable2 values are 18,19,20
As we are already using for each loop for DT2 to iterate and enter the data on an application
While entering DT2 values , i want to take the Datarow values also and enter.
For ex: bot is iterating 18 using for each loop,
I want to enter 1 also from datarow.
After completion of first iteration.
Bot moves to next iteration and takes 19,
I want to enter 2 from Datarow and so on
And yes the count of the datatable for both will be same
ppr
(Peter Preuss)
June 30, 2023, 9:29am
7
When nesting 2 loops you will get the by you reported issue
1,18 - 1,19 - 1,20
2,18 - 2,19…
As it will loop over all dt2 rows and the iterate to next dt1 row
For the requested case we shared:
Geeta
(Geeta)
June 30, 2023, 10:06am
8
I don’t understand how to use this
Geeta
(Geeta)
June 30, 2023, 10:33am
10
Hi
I don’t understand ColumnNameOrIndex meaning
Anil_G
(Anil Gorthi)
June 30, 2023, 10:35am
11
@Geeta
in the datatable you have columns right…index represents 0,1,2,3 for each column
and column name represents the name of the column in the datatable
cheers
ppr
(Peter Preuss)
June 30, 2023, 10:39am
12
Geeta:
ColumnNameOrIndex
A datatable has Data Rows and Data Columns
When accessing the data column value of a datarow we can use
Or
Example:
ID
Item
100
Apple
200
Mango
row(“Item”).toString will return Apple for the first Data row
row(1).toString will return Apple for the first Data row
Geeta
(Geeta)
June 30, 2023, 10:45am
13
You have used assign activity here for DT2 , how it is looping secondDT?
ppr
(Peter Preuss)
June 30, 2023, 10:52am
14
using the row index it is accessing the particular row directly.
Just implement it and explore it more while running / debugging it