Change column type action
- Updated: 2024/08/26
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
- DatetimeIf 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 |
- Create a bot.
- On the left panel, click Automation.
A list of available bots and forms is displayed.
- Click Create a bot.
- Enter the bot name: Change Column_Test.
- Click Create and Edit.
- On the left panel, click Automation.
- Double-click or drag the action.
- In the Session name field, enter Session 1.
- In the File path field, click Browse to provide the file path D:\userdefined\Test\Inventory.csv.
- Select the Contains header check box.
- In the Delimiter tab, select the Comma check box.
- Double-click or drag the action.
- In the Session name field, enter Session 1.
- In the Assign value to the variable field, create a table variable TableVar to save the output.
- Double-click or drag the action.
- In the Destination table field, select the variable TableVar.
- From the Insert column at index field, select last index.
- From the Insert column option, select Custom column.
- In the Column name field, enter Manufacturing Date.
- In the Column type field, select the data type as DateTime.
- In the Default value field, select DateTime and enter 12/14/2022.
- Double-click or drag the action.
- Click the Select Data Table drop-down menu and select TableVar variable.
- Select the Name tab from the Select column by field and enter Manufacturing date.
- Select Datetime from the Select the new column data type drop-down menu.
- Select Custom format from the Select date time format field and enter the value yyyy-M-d.
- Select TableVar variable from the Save the outcome to a variable drop-down menu.
- Double-click or drag the action.
- Enter $TableVar[4]{"Manufacturing date"}$ in the Source date and time variable field.
- Select Custom format from the Select datetime format field and enter yyyy-M-d value.
- Select SampleString variable from the Assign the outcome to a variable field.
- Double-click or drag the Message box to print the values. Select SampleString from the Enter the message to display field.
- Double-click or drag the action.
- Click Save and then run the bot.
The output is displayed as: