Import Before Row
The PHP code in the “Before Row” scripting area will be executed before each row of the import file is evaluated field by field.
It is very important to highlight the meaning of the $model variable.
The $model reserved variable is used to populate data of the entity that will be imported.
It is a PHP Object of the same type of the Model field specified in the Import. So, for example, if the Import is related to a DeepCmdb – Ci Model, then the $model variable will contain a Deep_Cmdb_Model_Ci Object. It represents a record of the Cmdb Ci Table in the Database.
It is also very important to highlight the meaning of the $data variable.
The $data reserved variable is used to expose data of the current Excel file row.
It is a PHP Array containing the values of every column of the Excel current row.
So, in the Excel reported above (see Table1), the variable $data will contain the following value for the first row of the Excel:
$data[0] = “106545” |
$data[1] = “Apple Iphone XI” |
$data[2] = “Mobiles” |
$data[3] = “Smartphones” |
$data[4] = “Active” |
$data[5] = “15/03/2019” |
$data[6] = “LFC6370742” |
$data[7] = “Scratches on the screen” |
$data[8] = “INTODEEP srl” |
$data[9] = “4\euler” |
Starting from the variables described before, the Before Row is used to retrieve a model from the database starting from an alphanumeric value.
So, for example, if a record must be loaded by CODE column in the Excel (see Table1) and not for ID, in the before row you can load the record with that code, starting from the Excel and the Database of Deepser.
In this case, the original DB record, once loaded into the $model variable, can be updated with the values in the current Excel file row, instead of creating a new record for every Excel row.