Change column type action

The Change column type action in the Data Table package enables you to change the data type of a column.

Settings

  • Click the Select Data Table drop-down menu and select an existing data table.

    If there is no existing data table, click the Create variable icon to create one.

  • Use the Select column by field to select one of the following tabs:
    • Name: Enter the column name.
    • Index: Enter the column index.

      For example, to set a value to the first column, enter 0.

  • Click the Select the new column data type drop-down menu and select one of the following option for column data type
    • Number
    • Boolean
    • String
    • Datetime
      If you select Datetime, you can format the values by selecting a predefined format or specifying a custom format.
      Note: To specify the format applied on the input data table variable, select an option either from the predefined format list or enter the value in a custom format
  • Click the Save the outcome to a variable drop-down menu and select an existing variable.

    You can either select the source table variable to overwrite the values or select a different table variable.

Example

In this example you will create an automation to change the data type of a column and print the values in a message box.

Before you start building the bot, create a file in .CSV format using the data in the following table and save it as Data_table_inventory.csv.
Product ID Product Name Expiration Date Quantity in stock
1 Formula milk 15-12-2023 50
2 Cereal bars 11-12-2023 80
3 Canned peas 20-12-2023 100
4 Sun dried cranberries 05-01-2024 40
5 Assorted nuts 15-03-2024 200
6 Assorted chocolates 18-12-2023 60
7 Castor sugar 11-12-2023 25
8 Breakfast cereals 01-07-2024 70
9 Protein bars 31-12-2023 45
  1. Create a bot.
    1. On the left panel, click Automation.

      A list of available bots and forms is displayed.

    2. Click Create a bot.
    3. Enter the bot name: Change Column_Test.
    4. Click Create and Edit.
  2. Double-click or drag the CSV/TXT > Open action.
    1. In the Session name field, enter Session 1.
    2. In the File path field, click Browse to provide the file path D:\userdefined\Test\Inventory.csv.
    3. Select the Contains header check box.
    4. In the Delimiter tab, select the Comma check box.
  3. Double-click or drag the CSV/TXT > Read action.
    1. In the Session name field, enter Session 1.
    2. In the Assign value to the variable field, create a table variable TableVar to save the output.
  4. Double-click or drag the Data Table > Insert column action.
    1. In the Destination table field, select the variable TableVar.
    2. From the Insert column at index field, select last index.
    3. From the Insert column option, select Custom column.
    4. In the Column name field, enter Manufacturing Date.
    5. In the Column type field, select the data type as DateTime.
    6. In the Default value field, select DateTime and enter 12/14/2022.
  5. Double-click or drag the Data Table > Change column type action.
    1. Click the Select Data Table drop-down menu and select TableVar variable.
    2. Select the Name tab from the Select column by field and enter Manufacturing date.
    3. Select Datetime from the Select the new column data type drop-down menu.
    4. Select Custom format from the Select date time format field and enter the value yyyy-M-d.
    5. Select TableVar variable from the Save the outcome to a variable drop-down menu.
  6. Double-click or drag the DataTime > To String action.
    1. Enter $TableVar[4]{"Manufacturing date"}$ in the Source date and time variable field.
    2. Select Custom format from the Select datetime format field and enter yyyy-M-d value.
    3. Select SampleString variable from the Assign the outcome to a variable field.
  7. Double-click or drag the Message box to print the values. Select SampleString from the Enter the message to display field.
  8. Double-click or drag the CSV/TXT > Close action.
  9. Click Save and then run the bot.

The output is displayed as:

Output displayed for the selected custom datetime format