How do i use nested for each loop in Uipath for the following scenario?

How do i use nested for each loop in Uipath for the following scenario

  1. For each should be for order number
  2. Nested for each should be line items
    image

How do i get this?

Consider the data is in data table DT1.

Create another Data Table variable DT2 and assign DT1, DT2 = DT1

For Each item in DT1 
         orderNumber = item(0)
         For Each item1 in DT2
            LineItem = item1(1)
         Next
Next
1 Like

Hi @Malika,

@ KarthikByggari mentioned code is correct only and need little bit changes to filter the DT2 according to Order number.

     For Each item in DT1 
       orderNumber = item(0)
       For Each item1 in DT2.Select("[Order Number]="+orderNumber,"ASC")
              LineItem = item1(1)
       Next        
     Next

But order number will not always be a sequential number.
It can have values - alpha numeric like SO1429, SO1856, etc.

any format of Order number does’t matter this the way to get line-items @Malika,

DT1 & DT 2 contain same data’s only,first DT1 iterate order number and filter DT2 with Order Number then you will get line items which is according to orderNumber.

if its possible send me your xaml file with data

What I meant is ascending will not hold relevant for Order number?

Sample xaml: can u share a sample xaml using nested for each for the above sample data?

its just an optional…if you want sort use it other wise leave it as empty quotes.

Hi @Mallika

You can also try to create a Temp Table with Distinct values of Order Number then select the rows from the Original Table and loop thru all the resulting rows, like…Nested Loops.xaml (12.4 KB)

I am getting an error like this:

Hi @Mallika

The For Each Row activity requires a datatable as its argument. You can use the For Each activity with the TypeArgument set like that:

I do not see that property option.

Select your activity for example for each and check on the right hand side ,you will see property option. Click on property .

try to convert as copytodatatable after filtering the table
ex:
DataTable2.select(“[Account Number]=”+AccountNumber,“”).CopyToDatatable()

Hi Did you get any solution for this? Please share