Answered question

How do I loop a transaction the number of times as values from a File variable?

Let's assume you have a File variable, but you are not always certain the number of values in it each time. You want to run 2 or more loops using this file variable in each one, and don't want to use each value more than once. How can you automate this so it only runs the looped transaction an exact number of times that you have values in the File variable?

You need to use Javascript logical action and code to parse your File used in the File Variable to get a line count. This line count value can then be used to run your loop count an exact number of times matching your values in the file.

Here is an example of the code you would use:

//Declare file with variable. Modify to match the path to your file variable.
var fileName = "C:\\Users\\NeoloadGuru\\Desktop\\Account.csv";

//Read File and get line count
var reader = new;
while ((reader.readLine()) != null) {}
var lineCount = reader.getLineNumber();

//modify value by subtracting 1 from value if file variable has a column header line, otherwise don't use.
var lineCount = lineCount-1
//Log value of line count from file
logger.debug("Line number is = "+lineCount);

//Export variable with value of line count back to Neoload script.


Now, this will parse the file to get a line count of values in the file. It can subtract 1 from the total to account for a column header, and export that line count value back to Neoload to use in the Loop Count.

Please refer to attached sample project for details.

Did you find this useful ?

No (0)

Yes (0)

0% of users found this answer useful