Skip to main content

Overview

dataHandler

Use our dataHandler feature on top of our cleaning functions to solve complex and complicated import scenarios. Take advantage of the advanced data access directly after the upload or after the mapping to customize your importer to suit your requirements.

DescriptionThe dataHandler is a powerful tool that can be executed before the “Header Selection”- and/or “Review Entries”-step, providing access to the original data and its metadata as well as enabling you to add/remove columns and rows. It can be configured to run based on your needs.
With the dataHandler function, you can solve complex data manipulation scenarios, such as transposing data, merging and splitting columns, joining sheets, de-nesting data, and more. Unlike other cleaning functions that iterate through every entry, the dataHandler function works on the entire data at once, giving you complete control over input data.
In addition, with the dataHandler function, you can add, delete, and modify columns and rows in the data, providing even greater flexibility in data manipulation.
Whether you need to transform a single column or an entire dataset, the dataHandler function provides the flexibility and power required to do the job effectively and efficiently.
Run EventThe execution of this function can occur before the “Header Selection”- or before the “Review Entries”-step, or even both, depending on the configuration.
Parametermodifier: The modifier parameter is a function that enables modifying the data by adding or deleting columns and rows. This function allows customization of the data per your requirements. The modifier function includes the following sub-functions:
  • addRow() - Adds a new row to the data.
  • deleteRow()- Deletes an existing row from the data.
  • addColumn() - Adds a new column to the data.
  • deleteColumn() - Deletes an existing column from the data.
By utilizing these sub-functions, you can manipulate the data in a granular manner to meet your specific use case.
data: The data parameter is a data structure that provides detailed information about the imported file(s). It includes attributes such as the file size, file name, and file extension, as well as the original data of the input.
  • headerStep: data is an array of objects with the following properties:
    • fileSize - The size of the file in MB.
    • fileExtension - The extension of the file.
    • fileName - The name of the file.
    • data - Original data of the file.
    • sheetName - The name of the corresponding sheet.
  • reviewStep: data is an array of objects where each object represents a row.

Modifier

headerStep:index: Specifies the position in the data where the new row will be inserted. If you pass an integer value for the index, the new row will be added to that specific index. If no index is passed or the index is null, a new row will be created at the end of the data.
data: Comprises an array of arrays, where each inner array represents a new row of values to be added.
reviewStep:index: Specifies the position in the data where the new row will be inserted. If you pass an integer value for the index, the new row will be added to that specific index. If no index is passed or the index is null, a new row will be created at the end of the data.
data: The data for the review step can have two formats based on your use case:
  • Without errors - an array of objects where each key represents a column key, and the corresponding value denotes the data to be added to the new row.
  • With errors - an array of objects where each key signifies a column, and the corresponding value represents an object containing the cell value and its associated error information.

It should be noted that the addRow() function allows multiple rows to be added to the record at once.

dataHandler={{
headerStep: async (modifier, data) => {
// Adding a row as a 2D array
modifier.addRow({
index: 0,
data: [["Max", "Jordan"]],
});
},
reviewStep: async (modifier, data) => {
// Adding a row without an error
modifier.addRow({
index: 0,
data: [{ column_key: "Hans" }],
});
// Adding a row with an error
modifier.addRow({
index: 1,
data: [
{
column_key: {
value: "Charlie",
info: [
{
message: "This cell was automatically added.",
level: "info",
},
],
},
},
],
});
},
}}

Returning data

The dataHandler enables you to return the complete data set after making modifications. It offers the flexibility to choose whether or not to return the modified data. If you decide to return the data, the modifier operations will be applied to the returned data. Alternatively, if you opt not to return the data, the modifier operations will be directly applied to the source data.

Moreover, the dataHandler allows you to obtain the data in two distinct formats for each stage. This feature empowers you to select the format that aligns best with your specific use case.

headerStep:You can provide the data as a 2D array where each inner array represents a row.
reviewStep: You can provide the data in one of two formats, with errors or without errors:
  • Without errors - you must pass the data as a JSON array where each object represents a row. Every row object must consist of keys representing columns, with corresponding values representing the cell value.
  • With errors - an array of objects where each key signifies a column, and the corresponding value represents an object containing the cell value and its associated error information.
It is important to ensure that the keys of your JSON data should match the keys of the target data model (TDM).
dataHandler={{
headerStep: async (modifier, data) => {
const newData = data[0].data;
newData.push(
["id", "name"],
["12345", "Jason"],
["67890", "Max"]
);
return newData;
},
}}

Implementation example

In the given example, we display how to iterate through the data after the mapping with the reviewStep function. We implemented a logic that fills the addresscolumn by merging thestreet, city, and countrycolumns if these three columns contain data. We then remove thestreet, city, and country columns from the output schema.

<NuvoImporter
licenseKey="Your License Key"
settings={{
developerMode: true,
identifier: "product_data",
columns: [
{
key: "full_name",
label: "Full name",
columnType: "string",
},
{
key: "street",
label: "Street",
columnType: "string",
},
{
key: "city",
label: "City",
columnType: "string",
},
{
key: "country",
label: "Country",
columnType: "string",
},
{
key: "Address",
label: "Address",
columnType: "string",
},
],
}}
dataHandler={{
reviewStep: async (modifier, data) => {
const dataLength = data.length;
const newData = data;
for (let i = 0; i < dataLength; i++) {
const element = data[i];

if (!element.Address && element.street && element.city && element.country) {
newData[i].Address = `${element.street}, ${element.city}, ${element.country}`;
}
}

modifier.removeColumn("street");
modifier.removeColumn("city");
modifier.removeColumn("country");
return newData;
},
}}
/>

If you’re interested in exploring additional use cases, kindly navigate to our knowledge base available on the user platform.