SuiteCRM icon indicating copy to clipboard operation
SuiteCRM copied to clipboard

The value 0 isn't properly saved when importing record with certain field types

Open SinergiaCRM opened this issue 2 years ago • 0 comments

When doing an import of a record that contains the value 0 in a dropdown o decimal field, the system doesn't detect its value, and instead is saving the default value of that field

Issue

If we want to import a "0" value of a decimal field or a dropdown field (there is an item of the list with "0" as the internal value), the system doesn't save it properly

Expected Behavior

It should be saved as if any other value.

Actual Behavior

The default value assigned to that field is saved instead.

Possible Fix

We detected two possible Issues within the same procedure.

The first one seems clear: https://github.com/salesagility/SuiteCRM/blob/51e182b29271876a9518bcef0c5c313c4a273954/modules/Import/Importer.php#L277 The empty function will evaluate "0" as true and wont' sanitize the value, if needed. Therefore it could be replace for isset().

After that, within the same function, the saveImportBean() is called. That function will be calling the function populateDefaultValues() from the Bean. That has again the same condition: https://github.com/salesagility/SuiteCRM/blob/51e182b29271876a9518bcef0c5c313c4a273954/data/SugarBean.php#L550 empty($this->$field). It's the same case as before, the value will be evaluated as empty an the default value will be assigned.

We aren't sure about modifying the condition of the last one. It might be affecting other parts of the CRM. Any suggestion is appreciated.

Steps to Reproduce

  1. Create a dropdown or decimal field in Contacts module
  2. Import a record to the Contacts module adding any value in the field last_name and "0" values in the decimal/dropdown fields
  3. Check that an empty value (or default value) was set on those fields

Context

A 0 value is relevant in any given context.

Your Environment

SuiteCRM Version used: Version 7.12.6 Browser name and version: Versión 100.0.4896.88 (Build oficial) (64 bit Environment name and version: MySQL, PHP 7 Operating System and version: Ubuntu 20.04

SinergiaCRM avatar Jul 26 '22 16:07 SinergiaCRM