Data Import question: a way to concat 2 columns?

I have an import I need to do where in our old ancient system we had character limits on fields so a description is in the old database as name1 and name2 - 2 columns. I’d like to import those as one field - is there a way to concatenate 2 input columns and return that to be imported as a single field?

Hi @jon.craig,

I think Custom Attribute Binding Script is what you need.

But let me suggest a different approach (if you haven’t evaluated it yet): Why not create a new column in your file and implement this logic directly in the source file? Then you’ll be able to use the standard mapping (1 column → 1 entity field).

Regards,
Peterson.

1 Like

Hi,

exactly, there are multiple ways to achieve that. In case you want to go with a custom binding script the way to merge two file columns to one entity attribute would be to create a custom attribute mapper that is associated to the target entity attribute and one of the source file columns.

The custom binding script also allows you get the complete parsed data row in the variable dataRow

Entity

@Entity
class Customer {
  private String code;
  // ...
}

Input File

customerName, customerType, country
Mario David, SMALL, de_DE

Custom Attribute Binding for Attribute “code”

return dataRow['customerType'] + "-" + dataRow['country'].split("_")[0]

Resulting value for code is: SMALL-de

I have not tested it but generally this is how it works.

Alternatively it would also be possible to use a pre-commit script to perform the operation at the very end of the mapping (and right before the commit to the DB). See: GitHub - mariodavid/cuba-component-data-import: CUBA component for easy data import. The pre-commit script also has the ability to interact with the dataRow variable.

In case you need more examples on how to use the app components, you can also take a look at the various integration tests: cuba-component-data-import/modules/core/test/de/diedavids/cuba/dataimport/integration at master · mariodavid/cuba-component-data-import · GitHub

They cover the most cases of the import usage.

I hope this helps.

Cheers
Mario

Aha - this is exactly what I need. I didn’t know there was an ability to address other columns from a column’s binding script. I only knew about the rawValue variable.