Import Before Row Tutorial
Estimated reading: 2 minutes
In the following example the column “CODE” is checked. If it is not empty and another Device with the same code already exists, the device will be updated with data in the current row of the import file.
Without this check, a new device would be created.
/* the Excel file column with index 0 (column A) containing the CODE field is evaluated.
the $data array represents the current line of the import file and it has all
its values accessible via the Excel column index. The index starts from 0. */
$deviceCode = trim((string)$data[0]);
/* if the column containing the attribute 'CODE' is not empty */
if($deviceCode){
/* if a device with same CODE already exists
the $deviceArray array was created with key = CODE and value = instance of the device
in 'Before Run' area */
if(array_key_exists($deviceCode,$deviceArray)){
/* the instace of the device already present, with the same code, is assigned to
the $model object
$model object represents the current instance of the
Deep_Cmdb CI model (specified in the Model field of the import configuration)*/
$model = $deviceArray[$deviceCode];
}
/* the class_id attribute is set by default to 2 (Device) */
$model->setClassId(2);
}
else {
/* if 'CODE' is empty, the current model is set to null to avoid saving
any empty or incomplete records */
$model = null;
}