Issue with For Each Loop - Same Data Filling in All UI Elements

Hello UiPath Community,

I am currently working on an automation project in UiPath where I am facing a particular issue. I hope you can help me find a solution.

Problem Description:
I have an Excel sheet from which I am reading data, and I am using a “For Each” loop to iterate through UI elements, clicking on them, and filling in data. However, I have noticed that the same data is being filled in all the UI elements within the loop, despite expecting different data for each element.

Workflow Overview:

  1. I read data from an Excel sheet using the Excel activities.
  2. I use a “For Each” loop to iterate through a list of UI elements.
  3. Within the loop, I click on a UI element and attempt to fill in data from the Excel sheet.

I’ve attached screenshots of the relevant parts of my workflow for reference

@Aditya_Nalawade

As per your screenshot

It is evident that same data is filled for each ui element loop

That is because you have an outer loop which loops through rows…and inner loop will loop through elements…so for each row of outer loop inner ui element loop will tun for all elements…

So if you want each row to be populated in each element…

Then the loop shpuld change a little

Use for each ui element only…currentindex will give you the index which will be 0 ,1, etc for each iteration

Now instead of your outer datatable loop…use the index as your loop counter so dt.rows(currentIndex)("BHS Category").ToString eill give the corresponding row for each ui element…similarly other items too

Hope this helps

Cheers

1 Like

Do you mean something like this?
Sorry for the inconvenience, but I am new to all of this.

@Aditya_Nalawade

Yes perfect

Cheers

giving me this error :thinking:

image

@Aditya_Nalawade

  1. is the dt the same datatable used in read range?
  2. Is the coumn name exactly matchign…can you please check

cheers

Thank you so much, sir, for your assistance once more. It is working, but it is capturing data from the second row, excluding the header; rather, it filled in data from the third row

@Aditya_Nalawade

may be index is starting from 1 in the loop…please use currentindex-1

cheers

1 Like

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