Teneo Developers
Table of Contents
Was this page helpful?

Share to

CSV Helper

With ResourceHelper you can load the contents of .csv or .tsv files stored in Resources as an object. To use ResourceHelper, proceed as follows:

Installation

Add the file ResourceHelper.groovy to the Resources in your solution and set the path to /script_lib

For more details on managing files in your solution, see Resource File Manager.

Usage

  1. Add your .csv or .tsv file to the resources and set the path to /script_lib. Populate a variable using the following code (replace 'your_filename_here' with the name of your file):

Example for csv files:

groovy

1def myResourceData = ResourceHelper.loadCSV("your_filename_here");
2

Example for tsv files:

groovy

1def myResourceData = ResourceHelper.loadTSV("your_filename_here");
2

ResourceHelper assumes the first line contains the headers and those will be used as keys.

Example

If your csv/tsv looks like this:

FirstnameLastname
BuffySummers
OmarLittle
EllenRipley
JackSparrow

The resulting object will be:

[ [Firstname:Buffy, Lastname:Summers], [Firstname:Omar, Lastname:Little], [Firstname:Ellen, Lastname:Ripley], [Firstname:Jack, Lastname:Sparrow] ]