Is it possible to update a value from a database within a for each activity? What I’m trying to do is to set a flag in each row that it iterates. I’m doing this because it is a “for each within a for each”, so I need that when the main “for each” triggers the second, it skips the flagged rows.
If it’s possible please tell me how, I tried the next implementation:
Main For Each row in Datatable1
Get rows
Assign count = 0
Second For each row in Datatable2
- Get rows
- Assing count = count + 1
- If countcertain condition and flag = false (0, “NO”, etc) then
- Add datarow to Datatable3
- Assign Datatable2.Rows(count).Item(columntoupdate) = certainValue → adding flag
I did not understand totally, but i think - Passing count = count + 1 should be at the end of your for each datatable2 as it is updating the subsequent row for every iteration,not current. or you can just specify rowdt2(columntoupdate).
In the first “for each” I set count = 0 to reset the counter. In the second “for each” I use count = count + 1 before the If condition because I’m counting the rows and using the counter to write the flag. Is it clearer?
@vvaidya I’m sorry but I’m not following what you are trying to say. Could you please be more specific? How can I start from row 0? what does it have to do with the question about if I can update a value within a for each? Please give me a more specific answer or anyone else.
Since the rowindex of a datatable starts from 0(not 1)and your code seems to be updating value in next row(index+1) because of prior increment of count.Please try below and let me know if it working
Main For Each row in Datatable1
Get rows
Assign count = 0
Second For each row in Datatable2
Get rows
If count certain condition and flag = false (0, “NO”, etc) then
@vvaidya I did what you suggested and it did’nt work as expected, also I need to count the rows I’m working with too, so instead of moving the count activity to the bottom, I tried this:
Main For Each row in Datatable1
Get rows
Assign count = 0
Second For each row in Datatable2
Get rows
Assing count = count + 1
If count certain condition and flag = false (0, “NO”, etc) then
Add datarow to Datatable3
Assign Datatable2.Rows(count - 1).Item(columntoupdate) = certainValue → adding flag
Write line: Flag
I added a write line activity after updating the row to see if it was working but it is not. It writes some rows, but not all of them that meet the condition. The write line activity is inside the condition box and after the updating row (assign activity), so it should only write “S” (my equivalent to true) but it is also writing “N” and I can’t figure out why.
Hai! i need to update row.item(!) from by checking some string elements like{“differnece between”, “brief”,“explain”}from row.item(0).i used for each statment but i can check the elements but i cant update it so i need a help corejava.xlsx (10.6 KB)
this is the excel sheet