Consider a scenario where you cannot have a fixed template for collecting data. The columns in the data model depend on the end user's preferences and/or some other criteria.
For such cases, csvbox provides the flexibility to add unique dynamic columns for each import at run-time.
Basic Installation
You can configure dynamic columns via the installation code.
Here's a basic configuration that adds 2 dynamic columns qualification and experience.
Pass the dynamic columns that you want to add as an array input parameter to thesetDynamicColumns()method while initializing the importer.
It specifies the data type of the incoming data. Possible values are: text, number, email, date, boolean, regex, ip, url, credit_card, phone_number, currency, list, dependent_list, dynamic_list, dependent_dynamic_list, multiselect_list, and multiselect_dynamic_list.
Note: The special characters in the expression need to be escaped. You may use a tool like this for escaping.
ip
version
"version": “ipv4”
url
-
credit_card
-
phone_number
country_code
"country_code": "de"
currency
symbol
require_symbol
allow_space_after_symbol
symbol_after_digits
allow_negatives
parens_for_negatives
negative_sign_before_digits
negative_sign_after_digits
thousands_separato
decimal_separator
allow_decimal
require_decimal
digits_after_decima
allow_space_after_digits
Note: The array digits_after_decimal is filled with the exact number of digits allowed not a range, for example a range 1 to 3 will be given as [1, 2, 3].
In general, the dynamic columns are displayed only after the regular columns.
The positionparameter helps to re-order the position of the dynamic columns and get them displayed before or in between the regular columns.
The position value starts from 1 indicating the first position in the final column list. It is an optional parameter while defining the dynamic columns.
Receiving Dynamic Data
The data from the dynamic columns is available in the data destinations along with the data from the regular columns. Currently,dynamic columns are supported by the following destinations only:
In the API response JSON object, the dynamic data will be displayed inside the _dynamic_data object as shown below. The _dynamic_data object will be visible only if the dynamic columns are configured for the import. In the example below check lines 12 and 31.
[ {"import_id":79418895,"sheet_id":55,"sheet_name":"Products","row_number":1,"row_data": {"Name":"TP-Link TL-WN822N Wireless N300 High Gain USB Adapter","SKU":"AS-100221","Price":"33.00","Quantity":"3","_dynamic_data":{"qualification":"MBA","experience":"3" } },"custom_fields": {"user_id":"1002" } }, {"import_id":79418895,"sheet_id":55,"sheet_name":"Products","row_number":2,"row_data":{"Name":"EPower Technology EP-600PM Power Supply 600W ATX12V 2.3 Single 120mm Cooling Fan Bare","SKU":"AS-103824","Price":"95.35","Quantity":"8","_dynamic_data":{"qualification":"MA","experience":"6" } },"custom_fields": {"user_id":"1002" } },]
S3 Data Destination
In the AWS S3 file store, the dynamic columns will be added as new columns in the uploaded file.