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

gary1
Star Chef I
Star Chef I

Question: are you reading from a CSV or writing a CSV? I can't tell from your description. Can you provide more details?

 

While writing

I'd like to help but I still don't understand the problem.

Hello @gary1,

The requirement is to generate a CSV where the headers are dynamic.
Based on a field from the source, the CSV headers need to change.

I configured these headers using a lookup table mapped to the source field. However, I later realized that these formulas do not work in the CSV compose block.

Currently, I am generating the CSV using multiple if-else conditions. I wanted to check if there is a better or more efficient approach to handle this.