Reputation: 219
I have the following in my data flow - which in itself is in a forloop. Is there any way in the data flow to get it to produce the file if the count of the records is zero?
I've done something similar in the past but in the control flow before the data flow, but I can't do that here as the data flow exists in a forloop to import multiple files and extract them to different files depending on the conditional split.
So if there are 56 transactions and no refunds I would like the Refunds file not to be created, but at the moment it is creating an empty file.
Thanks
Upvotes: 2
Views: 1850
Reputation: 31775
There is no reason you can't do the same thing you've done in the past. Inside the forloop you can put a script task before the dataflow that analyzes whether the refund file will contain any records and executes logic accordingly.
Upvotes: 0
Reputation: 1255
You can do it in the Data Flow Task level with Script component instead of using a FF Destination.
Delete the FF destination in the Refund branch and instead add a Transformation Script Component. (Add name spaces: System.IO and System.Text) Add the following code inside public class ScriptMain : UserComponent.
StringBuilder FileContent = new StringBuilder();
int count = 0;
public override void PreExecute()
{
base.PreExecute();
}
public override void PostExecute()
{
base.PostExecute();
if (count != 0)
{
File.WriteAllText("C:\\MyFile.txt", FileContent.ToString());
}
}
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
FileContent.Append(Row.COLUMN);
count = count + 1;
}
Upvotes: 1