Loop

how can i loop a process which has 2 different values in one of the column in excel for example “NP” and “SP”. example there are 3 rows containing “NP” and 2 rows containing “SP”

i want to be able to submit the necessary information for “NP” first then move on to the rows containing “SP”

Hi @meenyi

Can you try like below

' Filter the DataTable for "NP" rows
npDataTable = dataTable.AsEnumerable().Where(Function(row) row("ColumnName").ToString().Trim() = "NP").CopyToDataTable()

' Filter the DataTable for "SP" rows
spDataTable = dataTable.AsEnumerable().Where(Function(row) row("ColumnName").ToString().Trim() = "SP").CopyToDataTable()

' Process "NP" rows
For Each row In npDataTable
    ' Process the necessary information for "NP"
End For Each

' Process "SP" rows
For Each row In spDataTable
    ' Process the necessary information for "SP"
End For Each

Regards,

how can i then use an if activity perhaps such that after it processes “NP” if the next row doesnt contain “NP” and contain “SP” instead then it will proceed on to process for “SP” instead

meaning i want to make it in a way if its not “NP” then it will process “SP”

regards

@meenyi

’ Loop through each row in the DataTable
For Each row In dataTable
’ Use an If activity to check if the column value is “NP”
If row(“ColumnName”).ToString().Trim() = “NP”
’ Process the necessary information for “NP”
Else
’ Use another If activity to check if the column value is “SP”
If row(“ColumnName”).ToString().Trim() = “SP”
’ Process the necessary information for “SP”
End If
End If
End For Each

Regards,

when trying to assign the npDatatable, im met with this error, how do i solve it? thanks

Argument ‘Value’: BC30469: Reference to a non-shared member requires an object reference.

regards

@meenyi,

Simply use two For Each Data Row in Data Table activities and iterate your DataTable.

In First loop add condition to check if datarow.Item(“your column name”).ToString=“NP” If true then do the action.

In second loop add condition to check if datarow.Item(“your column name”).ToString=“SP” If true then do the action.

Thanks,
Ashok :slight_smile:

is it possible to show it in UiPath, i dont get what you mean thanks!

regards

@meenyi,

Input file:
image

Output File:
image

Solution:

Sample Code:
DT Demo.xaml (11.5 KB)

Thanks,
Ashok :slight_smile:

is it a must to have the 2 assign activity? thanks

regards

@meenyi,

Yes, if you have to take some action and then change the status of that row.

Thanks,
Ashok :slight_smile:

hi however, i do not have to have another row in excel like the “Status” row, what i need is to read either “NP” or “SP” then to correctly select the correct dropdown list on an website.

i tried using the if condition the CurrentRow.Item(“ColumnName”).ToString = “NP” and under the Then activity of this if condition i used a type into activity to navigate to the corresponding dropdown list. However, it doesnt execute this type into activity. Why is this so? Thanks

Regards

@meenyi,
For dropdown, you should be using Select Item activity. This should work.

Thanks,
Ashok :slight_smile:

hii select activity doesnt work for me :frowning:

may i ask if there is a way like previously i used chunk size to divide into chunk of 4 then the next time it loops, it skips the first 4 rows and runs the next 4 etc.

is there a way to use similar method but instead of using chunk size, i use similar words that are contained in the column.

for example if there are 5 rows with first 3 rows containing “NP” in row 1 to 3 and row 4&5 containing “SP”

so the first loop would run the rows containing “NP” then the next time it loops, it skips the rows containing “NP” and run the next rows containing “SP” etc
thanks

regards

@meenyi,

This two loop logic also working the same way. It will process “NP” first and then “SP”. Even if we are able to chunk by the SP/NP your select activity not going to work with that as well.

Thanks,
Ashok :slight_smile:


okay so does the 2 for each row in data table means if it doesnt contain “NP” then is will automatically proceed on to the for each row in datatable which contains “SP” , the second for each row in datatable

regards

@meenyi,

Yes, it will!

Thanks,
Ashok :slight_smile:

UiPath

hello!! may i ask if there is a way like previously i used chunk size to divide into chunk of 4 then the next time it loops, it skips the first 4 rows and runs the next 4 etc.

is there a way to use similar method but instead of using chunk size, i use similar words that are contained in the column.

for example if there are 5 rows with first 3 rows containing “NP” in row 1 to 3 and row 4&5 containing “SP”

so the first loop would run the rows containing “NP” then the next time it loops, it skips the rows containing “NP” and run the next rows containing “SP” etc

please help!

regards

thanks! however when i set the first row in excel to contain “SP” it didn’t proceed on to the second for each row in data table activity instead it still run the first for each row table

it is suppose to move onto the second for each row in data table activity as “SP” is stated instead of “NP” but it is not doing so

regards

@meenyi,

Let’s just separate the data as per Col1

We will have dtNP & dtSP

dtNP=dt1.Select("[Col1]='NP'").CopyToDataTable
dtSP=dt1.Select("[Col1]='SP'").CopyToDataTable

This way until and unless there are rows in respective datatable, it will not go to that for each.

Sample code:
DT Demo.xaml (12.4 KB)

Thanks,
Ashok :slight_smile:

hii! i tried this method but it is not working, i tried printing out the values for this datatable but it didnt give me anything, please help! thanks

this is my code in UiPath:
Datatable1.Select(“[Client e-Service Group]=‘SP Project’”).CopyToDataTable

this is how my excel looks like and my process flow:
image

regards