Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Support (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=6)
-   -   Adding Header into CSV file (http://www.mirthcorp.com/community/forums/showthread.php?t=218652)

luis.lay 10-10-2018 12:47 PM

Adding Header into CSV file
 
Hello,

I have a channel in v3.6.1 that creates a CSV file from database reader query. I need the CSV to show the query headers. If I add it the template destination (file writer), it adds the header per row. Is there a way to just add it once?

siddharth 10-10-2018 08:47 PM

There is. It is inside the data type properties on the inbound/outbound message templates.

agermano 10-12-2018 08:30 AM

It's easy if you are using mirth 3.5+ and your result set is small enough that you can aggregate results. It's a little more difficult if you are processing one row at a time and appending to the file. What kind of database are you querying from?

luis.lay 10-29-2018 08:33 AM

Hi,
I am querying from Oracle. I am using Mirth 3.5. What would be the best way to do it?
Thanks!

agermano 10-29-2018 05:50 PM

If you are doing aggregate results, that means your entire query will produce a single message.

See this thread for how to quickly convert database reader input to delimited text output in a transformer: https://www.mirthcorp.com/community/...d.php?t=217724

Your csv headers are just another row of data to the serializer. After the results are converted in the previous step (or you manually construct tmp) you can insert a new row at the beginning of your outbound variable that contains your headers (which can be grabbed from msg children.)

You can do the same thing if you aren't using aggregate results, but then you must be able to know which row of the result set you are on, so that you only insert the headers before the first row.

I recently opened a request to make that information available in the sourceMap as it is for File Readers. You can vote for it if you think it would be beneficial to you: http://www.mirthcorp.com/community/i...wse/MIRTH-4334

In oracle, you can add ROW_NUMBER() as a column in your query so that you can check if you are on the first row of the results. https://docs.oracle.com/cd/B19306_01...nctions137.htm


All times are GMT -8. The time now is 10:06 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation