Login to participate
Endpoint Management & Virtualization BlogsRSS

Workflow Tutorial: Integrating CSV Files

Craig Walker's picture

Readin', writin' and CSV files. Sounds like a good time. Create a project to make a copy of the selected CSV file using the ReadCsvFromFile component and the WriteDynamicDataToCsv component.

Prerequisite: A file saved in the CSV format. A sample can be created using Microsoft Excel.

Objective: To learn how to use the ReadCsvFromFile component, the WriteDynamicDataToCsv component and the WriteFile component.

Estimated time to complete: 30 minutes

Step 1: Create a new Decision Only project.

Drag and drop the ReadCsvFromFile and the WriteDynamicDataToCSV components from the Components palette under the Process Components / Dynamic Data category.

Drag and drop the WriteFile component from the Input Output / Files category.

Link the components together as shown below:

Step 2: Set the Input Data as shown below:

Step 3: Right click on the ReadCsvFromFile component and select Edit Component. Click the selector box next to the File field. Select 'CSVFile' as the variable name. Also, in the Output Variable Name selector box set it as 'RetValue'.

Step 4: Right click on the WriteDynamicDataToCSV component and select Edit Component. Click the selector button next to the Collection field. Click on the Add Array button in the Variable Data tab and set the variable as 'RetValue'.

Step 5: Click the selector button next to the File field. Select 'CSVFile' as the variable name.

Step 6: Right click on the WriteFile component and select Edit Component. Set the File Variable Name as 'CSVFile'.

Step 7: Set the Output File Name by entering a file path in the Constant Value tab e.g. e :\newcsv.csv

Step 8: Save and Run the project. Click the Run project button on the toolbar (bug with green arrow over it).

Step 9: Double click Execute and click the selector button next to the CSV File field. Click the selector button next to the Contents field.

Step 10: Select a CSV file and click Open.

Step 11: The results are displayed in the Execution window. In the respective folder a copy of selected file will be created with the given name.

Step 12: Finished!

scottwed's picture

Change title to CSV not CVS

Change title to CSV not CVS

Admin's picture

Thanks

Ah, that makes much more sense ;-)

Thanks for the feedback, Scott.

JM

Robert Lundsten's picture

Manipulate data

Hi!

How can I manipulate the CSV data before writing it to the file again?
I want also want to read and present the CSV data in a grid. Is that possible?

Thanks!

Robert Lundsten
Senior Technical Advisor

Asterio | http://www.asterio.se
Symanji | http://www.symanji.se

ChrisBern's picture

Both possible

a) The CSV data that gets read in will be available in your Workflow process stream as an array (aka a collection).  So you can work with the data in an array through various components, e.g. the ones in the Collection Handling category of the Workflow toolbox.  For example you could filter items out of the array with the Configurable Collection Filter, or loop through the array with a For Each Item in Collection.  Once you've manipulated the data, you could write it back out to a CSV file as described in the article above.

b) Yes, you can display the data in a grid.  Just figure out what data type the CSV data came in as (it's probably DynamicDataType or something similar).  You can right-click on a downstream component, click Browse Data, checkmark Show Type Name, and that will tell you what data type your CSV data is.  Then choose that data type on your grid, and choose to show an Array process variable, which will of course be your CSV array.  There are many videos on Connect and www.workflowswat.com that cover these and other fundamental Workflow techniques.

Robert Lundsten's picture

Thanks

Great answers. This will help me forward.

Thanks!

Robert Lundsten
Senior Technical Advisor

Asterio | http://www.asterio.se
Symanji | http://www.symanji.se