I had a scenario where I need to write correlation values in a CSV file. And the easiest way I had come up with is the below code in answer section.
More suggestions are appreciated.
Be aware that starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting so consider migrating to the JSR223 PostProcessor and the following code:
new File('FILEPATH/filename.csv') << vars.get('PARAM_1') << ',' << vars.get('PARAM_2') << System.getProperty('line.separator')
However this approach will work only if no concurrency assumed, if the PostProcessor will be executed by 2 or more concurrent threads you may run into a race condition when multiple threads will be writing into the same file resulting in data corruption.
So I would recommend declaring your PARAM_1
and PARAM_2
as Sample Variables and storing them into a file using i.e. Flexible File Writer