Validation Functions
Validate data with custom Javascript functions.
Last updated
Validate data with custom Javascript functions.
Last updated
If the validations you require are not covered with the in-built data type validations in CSVbox then you can code your own custom validation functions in Javascript.
There are two types of Validation Functions: 1. Row Functions 2. Column Functions.
Row Functions run validation on each row of data and return an error message (if any) for the user. These functions run at the beginning of the "validate" step and then also when a row data is updated during the "validate" step. An example use case for Row Function is if you want to mark a cell as "mandatory" based on a specific value in another cell in the same row.
Column Functions run validation on a set of selected columns when the user clicks the Submit button on the "validate" step. These are best used in cases where entire column data is required for validation. For example, say you want to find duplicate entries in a column. You could grab all the values in the column, find duplicate values, and display the message to the user.
Go to the edit sheet page > Columns tab > Click Add Functions button.
Add Function Name.
Select Row under Function Type.
Provide Javascript code.
Click Save.
Column 5 is mandatory only if the column 4 is not null.
You have access to data variables included in the csvbox
object. The following data is available:
csvbox.row
It contains row data. Each cell in the row can be accessed by providing the column name. Examples:
The column name must exist on the sheet or an error will be thrown.
csvbox.user
It contains the custom user attributes defined while initializing the importer. Examples:
csvbox.import
This refers to the current import-specific data. The following data is available:
console.log(csvbox);
With this statement, you can print all the available variables in the debugging console,
CSVbox will expect the Row Function to return an array of errors. Each error should specify the column
the error appeared in, and a message
to be displayed in the UI.
column
string
message
string
The message that is to be displayed to the user on the validation screen of the importer.
Go to the edit sheet page > Columns tab > Click Add Functions button.
Add Function Name.
Select Column under Function Type.
Add the Columns you need in the function.
Provide Javascript code.
Attach Dependent libraries (optional).
Click Save.
You can also enter the Dynamic Column names to access them in the Validation Functions.
Check if a column has duplicate entries.
In the Column Function Javascript snippet, you can utilize an external library that is hosted via a CDN. You can also call any external API endpoint to fetch real-time data. Simply add the library script tag and/or any custom scripts to the 'Dependencies' section and start using it in the main Javascript snippet.
You have access to data variables included in the csvbox
object. The following data is available:
csvbox.column
It contains the entire column data. Each cell in the column can be accessed by providing the column name and the row number. The row number starts with 1. Examples:
Only the selected columns will be available in the Column Function.
csvbox.user
It contains the custom user attributes defined while initializing the importer. Examples:
csvbox.import
This refers to the current import-specific data. The following data is available:
console.log(csvbox);
With this statement, you can print all the available variables in the debugging console.
CSVbox will expect the Column Function to return an array of errors. Each error should specify the row_id
, the column
the error appeared in, and a message
to be displayed in the UI.
row_id
integer
The row number of the error. Starts with 1.
column
string
message
string
The message to be displayed to the user on the validation screen of the importer.
The of the error. It is case sensitive.
The of the error. It is case sensitive.