If you want your robot to touch lots of things without crashing into a wall of casting errors, mastering the UiPath For Each activity is mandatory. This article walks through using For Each and For Each Row for lists and DataTable automation. You will learn how to pick the right TypeArgument, avoid the modern art of exceptions, and log progress so your manager does not ask why the bot failed on a Tuesday.
Begin with a Sequence or a Flowchart and declare variables for the collection you plan to iterate. Use an array or a List for simple text lists. For spreadsheet or table work load the table first with a Build Data Table activity or a Read Range activity. That gives you a DataTable to feed into For Each Row or to filter before looping.
Drag a For Each activity into your workflow when you have a generic collection such as an array or a List. Set the TypeArgument to the collection element type. For a list of text choose String. For lists of objects set the specific object type. If you are iterating rows use the For Each Row activity or set TypeArgument to DataRow in a For Each activity. Choosing the correct type prevents those cryptic casting errors that look like modern art.
Use the item variable name supplied by the activity. For DataRow scenarios access columns like this row("ColumnName").ToString when you need a text representation. Use Assign activities to transform values and Click or Type Into activities to push data to applications. Pick descriptive variable names so future humans can understand the loop without summoning a séance.
Wrap risky actions inside a Try Catch block and handle specific exceptions. Set ContinueOnError only when skipping an error is an acceptable business decision. Otherwise handle the exception and log details. Proper logging helps trace unexpected data and keeps stakeholders from asking for a miracle.
In short use For Each for collections and For Each Row for DataTable rows. Set a correct TypeArgument, filter data before looping, log progress, and catch exceptions with purpose. Follow these steps and your workflows will be less flirty with failure and more dependable for real world automation. Now go build something that works and enjoy the rare thrill of an unattended robot that actually finished its work.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.