# Uploading Data From CSV Using Batch Activities

> Upload entity records from a CSV file using Data Service batch activities in Studio, with a 1,000-record-per-call limit.

## Tutorial Overview

Batch activities accept and return a `List<T>` of entity records as input and output for creating, updating, or deleting multiple items.

These activities can accept up to 1,000 records in a single call and each activity call will count as one call against your service usage quota.

To understand how to use batch activities in Data Service, download the example below and follow the steps in this tutorial. The example creates 50 records for an entity via 2 batch activity calls.

[Download example](https://forum.uipath.com/uploads/short-url/32e186uENGqTgIPJu76RcSpy8ml.zip)

To run the downloaded example:

* Connect to your UiPath organization.
* Make sure Data Service is enabled in your tenant.
* Create the entity from the example.
* Connect the corresponding Orchestrator tenant to the UiPath<sup>®</sup> Robot.

Workflows containing batch activities typically include a **For Each** loop to iterate thought the records list, and to populate the `List<T>` list variable. The variable is then passed to the batch activity as input.

## Collecting Data

The `States.csv` file contains the records that the batch activity adds to your Data Service entity.

To run the batch activity, create an entity that has the same fields as your data.

![docs image](https://dev-assets.cms.uipath.com/assets/images/data-service/data-service-docs-image-47168-a7f1cddb-ebef61c4.webp)

## Creating the Entity

1. Go to the Data Service instance of your tenant.
2. **Create New Entity** called **US States** with the following fields:

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/data-service/data-service-docs-image-47388-e0126da1-3ddaf982.webp)

## Designing the Workflow

1. Open Studio and start a new process.
   :::note
   Make sure the Data Service enabled tenant is connected to the UiPath<sup>®</sup> Robot.
   :::
2. Install the **UiPath.DataService.Activities** pack.
3. Import the previously created **US States** entity inside your workflow in Studio.
4. To read the data from the `States.CSV` file to a data table, drag and drop the [Read CSV](https://docs.uipath.com/activities/docs/read-csv-file) activity.
   * In the **Read from file** field, enter the name of the CSV file.
   * In the **Output to** field, set a name for the data table.
5. Set a variable to store the batch size (i.e, how many records to alter in a call). Use the [Assign](https://docs.uipath.com/activities/docs/assign) activity.
   :::note
   The batch size is limited to 1,000 records. To alter more than 1,000 entries, set the batch size to 1,000.
   :::
6. Set a variable to store the list of records (for example, `listUSStates`). Use the **Assign** activity and initialize the list type to `New <List(Of USStates)>`. This creates an empty list, ready to be populated with the data from the CSV file.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/data-service/data-service-docs-image-47004-81db868a-d2ef6d21.webp)
7. To iterate through every row in the previously created data table (step 4), use the [For Each Row in Data Table](https://docs.uipath.com/activities/docs/for-each-row) activity.
8. For each row in the data table, create a new variable (i.e, `currState = New USStates`) and set the values for the US States entity fields (i.e, `State`, `DateofAdmission`, `Population`). Use the [Multiple Assign](https://docs.uipath.com/activities/docs/multiple-assign) activity.
9. To add the current state to the `listUSStates` list, use the [Append Items To Collection](https://docs.uipath.com/activities/other/latest/workflow/append-item-to-collection) activity.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/data-service/data-service-docs-image-47503-93ede540-42b47241.webp)
10. After each addition, check if the list size has become equal to the batch size you set at step 5. Use the [If](https://docs.uipath.com/activities/docs/if) activity with the condition `listUSStates.Count = batchSize`. The workflow continues to add records until the **If Condition** is met.
11. When the list size matches the batch size, create the records using the [Create Multiple Entity Records](https://docs.uipath.com/activities/docs/create-multiple-entity-records) activity. In our example, this creates 25 records using a single call.
12. Clear the collection after each batch of records, so the count for the next batch starts from zero.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/data-service/data-service-docs-image-47132-1e8e7e4b-4ef21af8.webp)
13. Outside the **For Each** loop, check if there are any remaining records in the collection and create them.

    This final step is important to cases where the records count isn't a multiple of the batch size. For example, if the collection contains 80 records, the **If Condition** at step 10 is satisfied for 25, 50, and 75 records (multiples of 25, the example batch size). The remaining 5 records are resolved by the last **If Condition** outside the **For Each** loop.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/data-service/data-service-docs-image-47220-41f6db52-05691af5.webp)
