Break to Next Row in For Each Row

Hi all,

I’m looping through a Data Table using a For Each Row & running various pieces of validation, writing data, etc. against an in-house platform.

Wanting to know please if there is an activity or .NET code that can break to the next row of a For Each Row?

I know that you can break the For Each loop in its entirety, but I’m just seeking to get to a point in the workflow & have the robot “stop, move to next row in data table”.

Is there a way to do this, aside from workflow design?

Working with sensitive data/systems, so unable to share a workflow file or screenshots at the present time, unfortunately.

Thanks in advance for an help! :slight_smile:

Daniel

1 Like

Hi @dlp1980,

Did you try using the ‘If’ activity inside For Each Row ? Specify the condition under ‘if’ and exclude the rows on which you don’t want to perform the action and in the else you can specify your validation and other actions. I hope that works.

Hello @dlp1980

Here “Continue Activity” is not available now, do not know why but may be their thinking is different on this but in .Net you can use “continue” keyword for this usage.

Here what you can do is on what particular condition you wants to skip that row just pass that condition with “if Activity” and skip operations on that.It is simplest approach.

Other approach as well you can use

You can convert the datatable to list collection and use it’s “Skip” method. as well.

List<Your data type> list = new List<Your datatype>();

foreach(DataRow row in dataTable.Rows)
{
    list.Add((<Your Data Type>)row);
}

Then on list collection you can use this : using Linq because To start, you must include the System.Linq namespace. This provides the extension methods that act upon the IEnumerable implementations found in many common types such as arrays and Lists

list.Skip(1)

Regards…!!
Aksh

3 Likes

Thanks Aksh! :slight_smile:

Hello Aksh1yadav!
I would like to follow your “continue” aproach with .Net but I don’t know how to do it. Inside a “for each row” activity I have an activity with a “try & catch”. If I catch an exception, I would like continue with the next row of the datatable that I’m looping with the “for each row” activity. Just typing continue in a “invoke code” activity, doesn’t work, I get this error:

Main has thrown an exception

Source: Invoke code

Message: Error compiling code
error BC30781: ‘Continue’ must be followed by ‘Do’, ‘For’ or ‘While’. At line 1

Exception Type: ArgumentException

System.ArgumentException: Error compiling code
error BC30781: ‘Continue’ must be followed by ‘Do’, ‘For’ or ‘While’. At line 1

at UiPath.Core.Activities.Workflow.CompilerRunner.Compile(String code, Int32 errLineOffset)
at UiPath.Core.Activities.InvokeCode.GetCompilerRunner(String userCode, List`1 args, String imps)
at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

I’m not programmer so I’m not good with .net. How can I do it?
Regards

Hey @rodrigo.garcia

Better this Existing Thread is i guess what you need :slight_smile:
Check it out -

Regards…!!
Aksh