Datatables Lists and Custom Objects

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 8 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Mastering Data Structures in Desktop Automations: Datatables, Lists, and Custom Objects

Introduction: Why Data Structures Matter in Automation

When we talk about building desktop automations, we often focus on the "action" side of things—clicking buttons, typing into text boxes, or scraping content from a screen. However, the true power of automation lies in how we manage the data that flows through our processes. If you view an automation as a factory line, the actions are the machines, but the data is the raw material. If that material is disorganized, messy, or stored in the wrong "bins," your entire assembly line will eventually grind to a halt.

In desktop automation platforms, we primarily work with three core data structures: Lists, Datatables, and Custom Objects. Understanding how to use these structures effectively is the difference between a fragile, error-prone script and a professional, maintainable automation. Lists allow you to track collections of items in a specific order. Datatables act as the digital equivalent of an Excel spreadsheet, allowing you to manage rows and columns of structured information. Custom Objects (often represented as dictionaries or objects) allow you to group related pieces of data together, such as all the details regarding a single customer or invoice.

By mastering these structures, you gain the ability to process thousands of records efficiently, handle complex data transformations, and pass information reliably between different parts of your automation. This lesson will guide you through the technical nuances of these structures, providing you with the knowledge to build logic that is both flexible and resilient.


Not read yet

1. Understanding Lists: The Foundation of Sequential Data

A List is the simplest form of a collection. Think of it as a vertical stack where each item has a specific position, known as an index. In almost every programming environment, lists are zero-indexed, meaning the first item is at position 0, the second at 1, and so on. Lists are incredibly useful when you need to store a sequence of similar items, such as a list of file paths in a folder, a list of email addresses to process, or a collection of task IDs.

Practical Application: Managing File Paths

Imagine you are building an automation that needs to process every PDF file in a specific folder. You would use a "Get files in folder" action, which typically returns the results as a List of File objects. You can then iterate through this list using a "For each" loop.

// Example Logic Flow
1. Create a variable: FileList
2. Action: Get files in folder 'C:\Invoices' -> Store in FileList
3. Action: For each CurrentFile in FileList
4.    (Inside the loop) Open file, read data, move to 'Processed' folder
5. End loop

Best Practices for Lists

  • Initialization: Always initialize your list variables before adding items to them. An uninitialized variable can lead to null reference errors.
  • Filtering: Use filtering actions to reduce the size of your list early in the process. Processing 10,000 items when you only need to work with 500 is a common performance bottleneck.
  • Index Safety: Always check if a list is empty before trying to access a specific index (e.g., MyList[0]). Attempting to access the first item of an empty list will crash your automation.

Callout: Lists vs. Datatables A List is a one-dimensional collection of items. It is ideal for simple sequences where the order matters but the data structure is uniform. A Datatable is a two-dimensional structure (rows and columns). Use a List when you have a simple collection (like a list of names), and use a Datatable when you have structured data that resembles a database table or a spreadsheet.


Not read yet

2. Deep Dive into Datatables: The Workhorse of Automation

Datatables are the most powerful tool in your automation kit. A Datatable is essentially an in-memory representation of a grid. It consists of columns (defining the type of data, like "Date," "Amount," or "Status") and rows (the actual records). Because desktop automations frequently interact with Excel, CSV files, and SQL databases, the Datatable is the universal language used to bridge the gap between these sources.

Key Operations with Datatables

  • Creating a Datatable: You can create an empty table and define columns manually, or you can import it directly from an Excel file or a database query.
  • Filtering: You can use "Filter Datatable" actions to extract only the rows that meet certain criteria, such as "Status equals Pending."
  • Updating Values: You can iterate through rows and update specific cells based on logic (e.g., if the amount is over $1,000, mark the row as "High Priority").
  • Merging: If you have data coming from two different sources, you can merge them into a single Datatable for unified processing.

Example: Processing a Spreadsheet

Let’s say you have an Excel sheet with columns: InvoiceID, ClientName, and TotalAmount. Your task is to extract all invoices over $5,000 and write them to a separate report.

  1. Read: Use "Read from Excel" to load the sheet into a Datatable named InvoiceTable.
  2. Filter: Use "Filter Datatable" on InvoiceTable.
    • Condition: TotalAmount > 5000.
    • Output: HighValueInvoices.
  3. Process: Use a "For each" loop to iterate through HighValueInvoices.
  4. Write: Write the filtered data to a new sheet or a text file.

Note: When working with Datatables, always remember that the column headers are case-sensitive in many automation platforms. If your Excel header is "InvoiceID" but your code looks for "invoiceid," the automation will throw an error.


Not read yet

3. Custom Objects: Grouping Related Information

While Lists and Datatables are great for collections, sometimes you need to store complex information about a single entity. This is where Custom Objects (often called Dictionaries or Key-Value pairs) come in. A Custom Object allows you to group different data types under one umbrella.

For example, if you are automating a customer onboarding process, you might need to store:

  • CustomerName (String)
  • DateOfBirth (Date)
  • IsVerified (Boolean)
  • CreditScore (Integer)

Instead of passing four separate variables throughout your automation, you create one object called CustomerProfile. You can then pass this single object to different functions or sub-flows. This keeps your code clean and significantly reduces the number of variables you need to manage.

How to Implement Custom Objects

Most desktop automation tools provide a way to create an object and add "keys" to it. A key is just the name of the property, and the value is the data associated with it.

// Pseudo-code for creating an object
1. Create new object: NewCustomer
2. Add item to NewCustomer -> Key: "Name", Value: "John Doe"
3. Add item to NewCustomer -> Key: "Age", Value: 30
4. Add item to NewCustomer -> Key: "Status", Value: "Active"

When you need to retrieve this data later, you simply call the key: NewCustomer["Name"]. This is much more readable than trying to remember which variable holds which piece of information.


Not read yet

4. Comparison: When to Use Which Structure

Choosing the right data structure is a core skill for an automation developer. If you choose the wrong one, you will find yourself writing overly complex code to "work around" the structure's limitations.

Structure Best For Complexity Key Feature
List Simple, ordered sequences of items Low Indexed access (e.g., List[0])
Datatable Large sets of tabular, row-based data Medium Powerful filtering and bulk processing
Custom Object Complex, multi-attribute entities High Grouping disparate data types together

5. Advanced Techniques and Best Practices

Managing Large Datasets

When you are working with thousands of rows, memory becomes a concern. Loading a massive Excel file into a Datatable can slow down your entire machine. If you are dealing with huge datasets, try to perform your filtering at the source (e.g., use a SQL WHERE clause to get only the data you need from a database, rather than bringing the whole table into your automation).

Error Handling in Data Loops

One of the most common pitfalls is a loop failing because of a "bad" row in a Datatable. If your automation expects an integer in the "Amount" column, but one row contains "N/A" or a blank space, the loop will crash.

Warning: Input Sanitization Never assume your input data is perfect. Always include a "Try-Catch" block inside your loops when processing Datatables. If a specific row fails, log the error, skip that row, and continue to the next one. This prevents a single corrupt record from stopping a process that would otherwise complete 99% of its work successfully.

Keeping Code Maintainable

If you find yourself creating a massive, nested structure (e.g., a List of Datatables inside of a Custom Object), stop and rethink. While it might work, it will be a nightmare to debug six months from now. Keep your structures flat whenever possible. If you need complex data management, consider breaking the automation into smaller sub-flows where each flow handles one specific part of the data transformation.


Not read yet

6. Step-by-Step: Building a Robust Data Processor

Let’s walk through a common real-world scenario: processing a CSV file containing employee payroll data, calculating a tax deduction, and updating the status.

Step 1: Data Import

Use the "Read from CSV" action. Ensure you check the "First line contains header" option. This automatically converts the CSV into a Datatable where you can access columns by their header names.

Step 2: Iteration

Use a "For each" loop to go through every row in the Datatable. Assign the current row to a variable named CurrentEmployee.

Step 3: Transformation

Inside the loop, extract the Salary column. Since data from CSVs is often read as text, you must use a "Convert to number" action.

// Logic inside the loop
1. Set variable: Salary = CurrentEmployee["Salary"]
2. Convert Salary to Number
3. Set variable: Tax = Salary * 0.20
4. Update Datatable Row: Set column "TaxAmount" to value of Tax

Step 4: Cleanup

After the loop finishes, you might want to save the updated Datatable back to a new CSV file or upload the results to a web portal. Always clear your Datatable variable at the end of the script to free up system memory.


Not read yet

7. Common Pitfalls and How to Avoid Them

Pitfall 1: The "Off-by-One" Error

This is the classic programming mistake. If you have a list of 5 items, the indexes are 0, 1, 2, 3, and 4. If you try to access List[5], your automation will fail. Always check the length of your list before accessing an index, especially if the list size is dynamic.

Pitfall 2: Modifying a Collection While Iterating

Never delete or add rows to a Datatable while you are currently looping through that same Datatable. This confuses the automation engine and often leads to skipped rows or infinite loops. If you need to remove items, create a second "Clean" Datatable, add the items you want to keep to the new table, and use that one for the rest of your process.

Pitfall 3: Assuming Data Types

Automation tools are often aggressive with "type inference." It might decide a column is a "Number" because the first 10 rows are numbers, but then crash on row 11 because there is a text character. Always explicitly cast your data types (convert text to number, date to string, etc.) before performing calculations.

Tip: Use Debugging Logs During development, use "Write to log" actions to print the contents of your objects or the row count of your Datatables. Seeing the data in the output panel while the script is running is the fastest way to spot why a transformation is failing.


Not read yet

8. Comprehensive Key Takeaways

To summarize the critical concepts of this lesson, keep these points in mind as you design your desktop flows:

  1. Data Structure Selection: Choose the simplest structure that fits your needs. Use Lists for sequences, Datatables for grids, and Custom Objects for complex entities.
  2. Initialization and Cleanup: Always initialize your variables before use and clear them or dispose of them when done to ensure your automation remains performant and memory-efficient.
  3. Data Sanitization: Never trust the input. Always validate that the data in your Datatable matches the format you expect before performing math or business logic on it.
  4. Error Handling: Use "Try-Catch" blocks inside loops. This ensures that one bad data point doesn't cause a total system failure.
  5. Avoid Modifying Collections: Never add or remove items from a list or Datatable while you are currently iterating through it. Use a secondary collection if you need to filter or modify data during a loop.
  6. Readability: Use descriptive variable names (e.g., EmployeeList instead of Var1) and clear key names in your objects. This makes your automation self-documenting and easier for colleagues to understand.
  7. Performance: If you are dealing with massive datasets, filter the data as early as possible—preferably at the source—to keep your automation fast and responsive.

Frequently Asked Questions (FAQ)

Q: Can I convert a List to a Datatable? A: Yes, most platforms have an action to "Create Datatable from List." This is useful if you have a list of strings that you want to turn into a single-column table for easier processing.

Q: What is the maximum size of a Datatable? A: Theoretically, it's limited by your machine's RAM. In practice, once you cross 50,000 to 100,000 rows, you will see significant performance degradation. If you need to handle datasets of that size, consider using a database or an external script to handle the heavy lifting.

Q: Why does my Datatable column header keep disappearing? A: This usually happens when you write the Datatable back to a CSV or Excel file without explicitly telling the system to "Write headers." Check your "Write to file" action settings to ensure the "Include headers" checkbox is selected.

Q: How do I handle nested objects? A: If you have a Custom Object inside another Custom Object, you access it using a chain of keys: Customer["Address"]["ZipCode"]. While powerful, keep these chains short to avoid difficult-to-read code.

By following these principles, you will move beyond simple "click and type" automations and start building sophisticated, data-driven processes that are the backbone of any enterprise-grade automation strategy. Take the time to practice creating and manipulating these structures in a sandbox environment before deploying them to production. The time spent mastering these fundamentals will pay off ten-fold in the stability and scalability of your future projects.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.