Forums

csv-export and alias with two fields

frimi 20 May, 2016
Hi guys,
I don't find a solution for my problems (or I search to much... :? )

I want create an alias like
select concat (lastname,', ', firstname) as name
in the forms->Setup->CSVExport.

For example, I want "Miller, Michael" in the csv-file.

Theres only Columns/Titles, Data Path and so on, it's possible to set an alias for one field, but how can I set an aliasstatement with 2 ore more fields?

Michael
GreyHead 20 May, 2016
1 Likes
Hi frimi,

The simplest way to do this is to load the data using a DB Read action, then use a Custom Code action to loop through and process it before using the Data Path option in the CSV Export action to do the export.

Assuming that the DB Read has a model ID of 'my_data' the Custom Code will be something like this:
<?php
foreach ($form->data['my_data'] as $k => $v ) {
  $form->data['my_data'][$k]['name'] = $v['last_name'].', '.$v['first_name'];
}
?>

Bob
frimi 21 May, 2016
Answer
hi Bob,
it works fine! 😀 thank for your help.

Michael
This topic is locked and no more replies can be posted.