Nested For each row activities

Hello,

I am using for each row in DT1
and inside i am using for each row in DT2
the problem is that am getting right values from DT1
but for the second log message , it is always giving me the same value.
any healp pkease!

1 Like

Yes, the code is correct.

If we have two for loops like

  for(i= 0; i<10;i++){
          writeline(i);
          for(j=0;j<10;j++){
             writeline(j);
              break;
          }
    }

It will loop through the values of “i” and it will get the first value of “j” and break. so it will give only the first value. If you don’t use break there, it will print the first value of “i” and all values of “j”, then again second value of “i” and all values of “j” @teyssir1

2 Likes

i want to get first value of i , first value of j , the second value of i, second value of j … n value of i and n value of j.
what activity shall i add there?

1 Like

Actually this will work like this
–first log message will print the value of row(“Messag”).ToString
–followed by that as we have used for each row loop it will print all the values in the column phoneNumbers along the log message.
–again this inner for each row loop will close all the values of the phoneNumbers column is written
–now will go to the outer for each row loop where the next value i.e., next row value of column Message is written and again followed by that all the values in the column phoneNumber is written
i.e., same value will be written

and if we want the values to be printed one by one i.e., each row by row in that column phoneNumber then we need to remove the inner for each row loop and use only log message like this
"test2:" + dtReverse.Rows(ExtractDataTable.Rows.IndexOf(row))(“phoneNumber”).ToString

so the structure should be like this
–For each row loop with datatable ExtractDataTable1 as input
–then use a Log Message activity and mention like this
"test1: "+(row(“Message”).ToString)
–next use another log message like this
"test2:" + dtReverse.Rows(ExtractDataTable.Rows.IndexOf(row))(“phoneNumber”).ToString

–this will print the first row value of Message column from table ExtractDataTable1 and first row value of PhoneNumber column from the table dtReverse
and for the next iteration it will print the second value and it goes on

simple isn’t it
hope this would help you
kindly try this and let know for any queries ror clarification
Cheers @teyssir1

1 Like

Hey Teyssir1,

Solution is pretty simple… You should only use one For each Row. In the properties pane you will find the Output Index (see image).

This will be index of your for each row in ExtractDatable1, you can now address the same index of your second datatable by referring to DataTable.Rows(index variable)(Column index / name).

If you share your workflow I could implement it. Good luck.

Rgds,

Bas

image

1 Like

it works!
thank you :slight_smile:

1 Like

Fantastic
Cheers @teyssir1

Nice! Could you mark my answer as the solution for further reference of people with similar question.

Have a great day.

1 Like

i have an additional question,
in fact my two DT1 has 4 rows , and DT2 has 30 rows
i want to check only the first 4 rows of DT2 as DT1 has only 4 rowsCapture

1 Like

If you have a for reach row on DT1, it will stop at the last index of DT1 and thus not check the other 26 rows of DT2!

1 Like

Great

this method will actually work in the same way
but we need to make sure that the datatable which has only four rows must be passed as input to the for each row loop
while
the one which has more that 4 rows should be mentioned here in the highlighted area

–For each row loop with datatable ExtractDataTable1 as input //datatable with only 4 rows
–then use a Log Message activity and mention like this
"test1: "+(row(“Message”).ToString)
–next use another log message like this
"test2:" + dtReverse.Rows(ExtractDataTable.Rows.IndexOf(row))(“phoneNumber”).ToString //datatable with more than 4 rows

Cheers @teyssir1

1 Like

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