cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Handling Dynamic headers while composing a csv file

Bhagya_pola
Executive Chef I
Executive Chef I

Hello all,

Currently I have a crazy requirement where the headers of a csv file are dynamic, I noticed just now that I can't access any pills in formula mode in order to write a lookup formula for headers section in compose csv action.

Currently the only way I can think of is handling it with if and else conditions based on a field from input and compose csv accordingly.

Is there any other efficient way we can achieve this?

Thanks in advance.

2 ACCEPTED SOLUTIONS

shivakumara
Executive Chef III
Executive Chef III

Hi @Bhagya_pola ,

My perspective on this requirement is as follows:
Assuming contents (headers to be formed) are coming from application or from file.

  1. Extract the dynamic keys (headers) by writing a script in Python, Ruby, or JavaScript.
  2. Since the โ€˜Compose CSVโ€™ step requires the headers to be aligned with a newline (\n), we can generate that using a formula.

Using multiple IF/ELSE conditions would make the design overly complex and reduce readability.โ€

Try this approach and let us know if you need further help.

Thanks and Regards,
Shivakumara K A

View solution in original post

I wouldn't put the actual headers in the CSV compose action. In the action, name the columns something simple like "a,b,c,d,e" and generate the CSV without a header line.

Then, generate your dynamic headers however you want and simply "text add" the headers to the CSV output. You don't need Python or Ruby for this. You can do this in any input field.

It's as simple as:

"header1,header2,header3\n" + [CSV output datapill]

The headers could be another data pill or text.

Important: Don't forget the "\n" at the end to make a new line between the headers and CSV.

Check this post too. It's very similar to your issue and has the same solution:

https://systematic.workato.com/t5/workato-pros-discussion-board/csv-formatting-challenge/m-p/7994

If you're having trouble making the dynamic headers, then I would need to see your data source.

View solution in original post

8 REPLIES 8

I wouldn't put the actual headers in the CSV compose action. In the action, name the columns something simple like "a,b,c,d,e" and generate the CSV without a header line.

Then, generate your dynamic headers however you want and simply "text add" the headers to the CSV output. You don't need Python or Ruby for this. You can do this in any input field.

It's as simple as:

"header1,header2,header3\n" + [CSV output datapill]

The headers could be another data pill or text.

Important: Don't forget the "\n" at the end to make a new line between the headers and CSV.

Check this post too. It's very similar to your issue and has the same solution:

https://systematic.workato.com/t5/workato-pros-discussion-board/csv-formatting-challenge/m-p/7994

If you're having trouble making the dynamic headers, then I would need to see your data source.

Oh, looks like a great work around,
let me give it a try ๐Ÿ™‚

shivakumara
Executive Chef III
Executive Chef III

Hi @Bhagya_pola ,

My perspective on this requirement is as follows:
Assuming contents (headers to be formed) are coming from application or from file.

  1. Extract the dynamic keys (headers) by writing a script in Python, Ruby, or JavaScript.
  2. Since the โ€˜Compose CSVโ€™ step requires the headers to be aligned with a newline (\n), we can generate that using a formula.

Using multiple IF/ELSE conditions would make the design overly complex and reduce readability.โ€

Try this approach and let us know if you need further help.

Thanks and Regards,
Shivakumara K A

Hi @shivakumara ,
Thanks! Yes, Iโ€™m currently trying this approach and will see how it goes.