Import Binding the Type Value
Estimated reading: 2 minutes
The following example shows the code used to bind the “TYPE” field, assigning to the $model, the id of the Type which is specified using a name in the import file.
This example is very useful if we want to import data not with their keys, but with their alphanumeric (human readable) values.
/* $value contains the value of the current column in the import file, calling trim()
method (after casting as string type) to eliminate any space char at the beginning or
at the end of the string */
$value = trim($value);
/* if $value isn’t null and isn’t empty */
if($value){
/* if the type name exists in DeepDesk. This is checked by testing if the name in the Excel file is a
key in $subtypesTree array, created in the 'Before Run' scripting area */
if (array_key_exists(strtoupper($value), $subtypesTree)) {
/* the type id is retrieved from the subtypesTree array and saved in the field
type_id of the current model */
$model->setTypeId($subtypesTree[strtoupper($value)]['id']);
}
else {
/* if the type name specified in the file doesn't exist in DeepDesk, then type_id
is set to null */
$model->setTypeId(null);
}
}
else {
/* if no type name has been specified in the import file, then type_id
is set to null */
$model->setTypeId(null);
}