Retrieve values from a file for pre-request

Hi!

I’m running via a “runner” and need to retrieve a value from the input file .csv to manipulate it before the final execution.

My file has this information:

rut,data
103023440,4455005039211100
103023440,445528503929988

I need to retrieve only the first 6 characters from the “data” field:

var data = pm.iterationData.get(“data”);
var slicedData = data.substring(0, 6);
pm.environment.set(“sliced”, slicedData);

Then I can use it in the final request.

{{rut}}
{{data}}
{{sliced}}

But still, I’m unable to do it… the value isn’t retrieved from the file.

You can use the special data variable which will have a JSON representation of the current iteration\line in the CSV file.

Try the following…

console.log(data); // json representation of the current line of your CSV
console.log(data.data); // this should be your data column from the CSV file.
console.log(data.data.substring(0, 6));
pm.environment.set("sliced", data.data.substring(0, 6));

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.