Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

How to fetch labels on import file as rows?

Avatar

Level 1

I have a file import that has x-number of columns. I want to create an automated enumerator that updates it's values based on the column-labels of the import files.

But in order to do that, I need to transpose the column lables of the import file to values of a single column.

So - f.ex. the file looks like this:

Column1Column2Column3Column4Column5

Data 1

Data 2Data 3Data 4Data 5
Data 1Data 2Data 3Data 4Data 5
Data 1Data 2Data 3Data 4Data 5

I want to get this kind of result:

Label of Columns
Column 1
Column 3
Column 3
Column 4
Column 5

So I could then add the values of "Label of Columns" as Enumerator values to my enumerator.

How to do this (either via normal activities - which I doubt will bend to this - or with JS-code).

The main criteria are:

- Having a single column with the names of the columns of the imported file

- The number of columns can vary in the import file.

- Mikael -

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi Mikael,

In advance tab of Data loading activity

Add below code to get column header information. Once you get comma separated list of columns header just split this and save it in Enumeration. This is also dynamic in nature so number of columns can vary this will give you proper result.

1.  var colHeader = activity.source.dataSourceConfig.sampleLines.line[0]

2.  var arrayCol = colHeader .split(',') ;

3. Use for loop to have values and save this in ENUM.

I hope this helps.

Thanks,

Kapil

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi Mikael,

In advance tab of Data loading activity

Add below code to get column header information. Once you get comma separated list of columns header just split this and save it in Enumeration. This is also dynamic in nature so number of columns can vary this will give you proper result.

1.  var colHeader = activity.source.dataSourceConfig.sampleLines.line[0]

2.  var arrayCol = colHeader .split(',') ;

3. Use for loop to have values and save this in ENUM.

I hope this helps.

Thanks,

Kapil

Avatar

Level 1

Here's my final code just as an full example, I'm not a "proper" coder so it might not be the prettiest and there are some "cleaning" possible and the columns had 2 values I didn't want to put in the enumerator, so I rather crudely omitted them with two if/else clauses... but anyway: