Dynamic data import / export

datenbank

simply more productive
Up to 10,000 records can be processed with the freeware version!
Welcome, Guest
Username: Password: Remember me
Welcome to the FlowHeater support forum.

Questions about using FlowHeater are answered here.

TOPIC: CSV export: dynamic generation of file names

CSV export: dynamic generation of file names 5 years 11 months ago #2073

  • FlowHeater-Team
  • FlowHeater-Team's Avatar
  • Offline
  • Administrator
  • Posts: 239
Translated submission in the German forum. You can read the original entry here.

Hello,

We are exporting CSV data from an SQL Server and would like to dynamically generate the exported CSV file names.

In our case the exported data contains a date field, which we could use to compose the file name using the month and year.

Is there a straightforward way to address this requirement?
Many thanks in advance,

J.-U. Lein
Best wishes
Robert Stark

Did this answer your question? We would be grateful if you provide a brief comment as feedback. It may also help others who may have encountered a similar problem.
The administrator has disabled public write access.

Re:CSV export: dynamic generation of file names 5 years 11 months ago #2074

  • FlowHeater-Team
  • FlowHeater-Team's Avatar
  • Offline
  • Administrator
  • Posts: 239
Hello Mr Lein,

You can do this with the .NET Script Heater and the following short C# .NET Script.
public object DoWork()
{
	TextFileAdapter adapter = (TextFileAdapter)AdapterWrite;

	if (InValues.Length != 2)
		throw new Exception("2 input parameter required");
	
	// do not execute in test mode
	if (adapter.OnlyTest == false)
	{
		// Set the new file name in the TextFile adapter = second input parameter
		// WARNING: This method only functions when using the Mass Data mode.
		adapter.Filename = (string)InValues[1].GetString();
	}

	// just returning the first input parameter
	return InValues[0].GetValue();
}

Drag and drop a .NET Script Heater onto one of the existing connections.

Please note: This step is necessary, because without a connection to the WRITE side the script code it contains is never executed!

Now format the CSV file name as you require from your date field using Heaters/Functions and connect the dynamically generated string to the second input of the .NET Script Heater. The script will now set the CSV file name in the WRITE TextFile Adapter to this new name during the transform. The first input to the .NET Script Heater is passed through unaltered.

WARNING: This method only functions when using the Mass Data mode.

I have prepared a brief example for your requirement, see the enclosed "dynamic_csv_export_file_names.zip" file. The example uses the TestData Adapter on the READ side, just creating a handful of test rows for the purposes of illustration. The CSV file names are dynamically generated from a date field and formatted using the Format Heater. The String Append Heater concatenates all elements of the CSV file name together and passes the complete CSV file name to the second input of the .NET Script Heater.

Note: This example also demonstrates how several CSV text files can be written during a single export run. If the incoming dates differ and are not sorted in sequence (as in the example), you also need to check the option "Append to file" in the TextFile Adapter on the WRITE side.

Attachment dynamic_csv_export_file_names.zip not found

Attachments:
Best wishes
Robert Stark

Did this answer your question? We would be grateful if you provide a brief comment as feedback. It may also help others who may have encountered a similar problem.
The administrator has disabled public write access.
Moderators: FlowHeater-Team
Time to create page: 0.073 seconds