CSV to/from Database downloaded csv the field order is mixed up

Hi
I successfully did as per the instructions everything works but the only issue is when we use the tableto csv with the where filter and properties I have added selected fields . the csv file gets generated and when downloaded the order in which the fields are coming in the csv is not in the same order of list of fields mentioned in the properties.

kindly advise

regards

Hello, @dbasilapp.

I don’t really understand what you are trying to do. Please provide more details on how you are trying to export the file, attach screenshots and steps to reproduce.

Best Regards, Nikita.

but the csv coming out the fields are not in the same order

Patientmobile coming first column other columns coming in some other position

so the csv columns output is not exactly as we set in the codeless block

a full usage is show here

hello @dbasilapp

check your api service CSVAdapter and make sure that it returns data in one order all the time

Hi
I didnt understand, the issue is its not returning the csv in the same order as done with the codeless block.

regards

Hi
ok sorry, now i understood what you asked, csvadapter is taken from marketplace

I am trying to use that to allow users to download data from table based on a where and a list of selected fields

all working but the order in which the columns are in the downloaded or generated csv is mixed up.

regards

Hello @dbasilapp,

In order to set the sequence of the columns you need to provide a columns option in the csvOptions object:

{
  "filePath": "demo.csv",
  "tableName": "Person",
  "csvOptions": {
    "header": true,
    "columns": ["C", "B", "A", "E", "D"] // The order definition matters. It reflects the order of the generated records. 
  }
}

Keep in mind that if you use it with the columnsMapping option, you should specify mapped column names instead of original, e.g.:

{
  "filePath": "demo.csv",
  "tableName": "Person",
  "tableOptions": {
    "columnsMapping": { "A": "Foo", "B": "Bar" }
  },
  "csvOptions": {
     "header": true,
     "columns": ["C", "Bar", "Foo", "E", "D"]
  }
}

Regards,
Stanislaw

Hi Thank you that worked perfectly.

regards

Hi Stanislaw- would it be possible to show this example in a codeless block? I’m still not 100% following this thread.

Thanks!