Nested for each loop in Uipath

I have sample excel:
Against Column B, i have to load Coulmn C , D, E values
two loops:
Outer Loop for column B
Inner loop for column C to E
But how do i make it work in uipath?

Version used : image

May i know what you mean like load, kindly elaborate the scenario pls

I am populating data into a web application.
So first I populate agent ABC (Column B) and BU (Column A) at the header level of the application page.

Then against each agent and BU, I need to populate line details that is Column C, D and E.

So i want the bot to first enter the header details, then come to line details, iterate for all line details. ABC has 10 lines. So loop should run 10 times, stop and come to the outer loop.

Again as per outer loop, take the next agent MNO and poulate its line details, and this way.


Please follow below steps to do this.

  1. First useRead Range activity to read the data from excel file and will give you output as DataTable and say ‘inputDT’.

  2. And then find unique records based on Column Agent like below.

         agentDT = inputDT.DefaultView.ToTable(True,"Agent")
  3. And then use ForEach Row activity to iterate one by one agent data.

      ForEach row in agentDT
      filterAgentDT = inputDT.Select("Agent = '"+row("Agent").Tostring+"'").CopyToDataTable
       ForEach agent in filterAgentDT
               Pass values like this: 

Your scenario is Type of group by approach
For each col a, b group, handle the group of col c,d,e

Doing this can be done with e.g two loops, and filterdata. But also there are some variations in IT.

So Let US know which excactly Help you need and provide us an example with Sample data.on this Base WE can Help you with the Implementation or doing Dom Demo Implementation

are u using 3 loops?


I am trying to understand ur logic

  1. DT1 = for entire file
  2. DT2= distinct agent from DT1
  3. DT3 = each row in DT2
  4. DT4= filter agent…

I am confused. can u pls elaborate

@Mallika please Upload your excel.xlsx file., Not the Screenshot. In Case of prototyping WE can use this directly and do Not loose time in creating a sample Data File. Thanks

Yeah , u can take the attached Sample Excel.xlsx (9.3 KB) as sample.

@Ok will have a look on it give me some little time

some differences between excel and sample data form posts were encountered. However find attached demo xaml showcasing with log messages the different stages of the processing:


Logic as described above:
For each col a, b group, handle the rows col c,d,e belonging to the particular group

Demo XAML: Mallika.xaml (12.3 KB)
dont miss out to rewire the path your excel

Let us know your feedback and flag the solving post as solution. So others can benefit from it


Thanks and really appreciate your effort. I ran your xaml and it worked as expected.
But to be honest, i did not incorporate your logic as i found it complex for my understanding.

I took a simple approach, which solved my problem.

  1. DT1 = unique Agent and BU
    2 For loop for DT1
  2. DT2: Entire excel
  3. For loop for DT2.
  4. With in the nest for each loop, i put condition as if DT1. agent = DT2. agent
    then run the inner loop else come out of the inner loop

just this logic
i = 1 to 10
j = 1 to i

1 Like

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