Skip to main content
Virtual Columns are one of CSVbox’s most powerful data transformation tools. They run small snippets of JavaScript that merge, split, re-format, correct, and enrich incoming data during an import. Use them to process your data, do calculations, or merge values together before the data reaches your end.

How it works

1

Add a virtual column

For any sheet (template), add a virtual column in the CSVbox dashboard.
2

Attach a JavaScript snippet

Attach a JavaScript snippet to the virtual column.
3

Users submit the CSV file

After users submit the CSV file, the JavaScript runs to populate data in the virtual columns.
4

Data is pushed to the destination

Data from the uploaded CSV and the virtual columns is pushed to the data destination.

Example

Merge data from the first_name and last_name columns into a new virtual column named full_name.Here is the JavaScript attached to the full_name virtual column:

Adding virtual columns

1

Open the Columns tab

Go to the edit sheet page → Columns tab, and click the Add Virtual Column button.
2

Name the column

Add the virtual Column Name.
3

Provide the JavaScript code

Enter the Javascript code.
4

Attach dependencies (optional)

Attach Dependent libraries.
5

Save the column

Click Save.
Add Virtual Column dialog

Add Virtual Column

Data rows

Data rows are the core object that virtual columns are built around. For each incoming CSV data row, you can read its data and manipulate it with JavaScript to populate the virtual column. After the user submits the CSV, the JavaScript runs for each data row in sequential order to populate the virtual columns. Use the csvbox.row object to work with each row, and csvbox.row["column_name"] to read a specific column of the data row. You can use data from a single column, multiple columns, or no columns to populate virtual columns.

Inserting data into virtual columns

The value returned by the JavaScript snippet is added to the virtual column.
If the JavaScript returns a NULL value, an empty string is added to the virtual column.

Receiving virtual data

Virtual column data is available at all data destinations along with the data from the regular columns.
In the API response JSON object, the virtual data appears inside the _virtual_data object, as shown below. The _virtual_data object is visible only if virtual columns are added to the sheet. In the example below, check lines 12 and 31.
The virtual data is also available on the client-side JSON object.

Dependencies

In the JavaScript snippet, you can use an external library hosted on a CDN. You can also call any external API endpoint to fetch real-time data. Add the library script tag and any custom scripts to the Dependencies section, then use them in the main JavaScript snippet. For each import, the dependent scripts run only once, whereas the main JavaScript snippet runs once for each row.
Virtual column processing: dependencies run once, the snippet runs per row

Virtual Column Processing

Suppose you want to use the data from the incoming USD_amount column to create a new GBP_amount virtual column. The amount should be converted from USD to GBP using real-time exchange rates.You can use the Money.js library for currency conversions and Open Exchange Rates to fetch real-time conversion rates. Here is the sample dependency code:
Dependent Scripts
Corresponding JavaScript snippet for the GBP_amount virtual column:
Javascript snippet

Variables

In the virtual column JavaScript snippet, you have access to data variables in the csvbox object. The following data is available:

csvbox.row

Contains the row data. Access each cell in the row by providing the column name. Examples:
The column name must exist on the sheet, or an error is thrown.

csvbox.user

Contains the custom user attributes defined while initializing the importer. Examples:

csvbox.import

Contains data specific to the current import. The following data is available:

csvbox.virtual

Contains data from the preceding virtual columns.
Only data from the virtual columns defined before the current virtual column is available for use.

csvbox.environment

Contains the environment variables passed during importer initialization.
Use console.log(csvbox); to print all the available variables in the debugging console.