Feeding csv file with dynamic file name

Hi all, need a help on how to feed a csv with dynamic file name. In the below scenario, I am getting compiler error at Line 6 “No candidates found for method call session.getString(“filename”)”
Requirement: From the first csv, i get organization name and the new csv file name is “{orgname}.csv” which i want to feed again

   ScenarioBuilder scn = scenario("foo")
                                 session->session.set("org", session.getString("Org"))
                                         .set("filename", "Testdata/" + session.getString("Org") + ".csv"))
                                 String item = session.getString("I_Item");
                                 System.out.print("Org-->" + "item -->" + item);
                                 return session;

Hi @subhah,

Our feeder constructors (csv) don’t take session API as argument, they should be instantiated BEFORE the start of the simulation.

Feeders are meant to be shared between virtual users and it’s not possible if each user create its own feeder.

Your use case may be interesting, but you will have to manage your own way to manipulate session attributes based on previous values.

Feel free to share your solution with our community!

Good luck!

1 Like

Hi @sbrevet ,

Thanks for your response ! I tried different alternatives and in below code there were no compiler errors. However, line 8 prints correct value, line 11 printed “null”. “I_Item” is from second csv file. Seems the second csv is not getting into memory ?

1 public static String fname=“TestData/OrgwiseStores.csv”;
2 public static String fname1;
3 ScenarioBuilder scn = scenario(“foo”)
4 .feed(csv(fname).queue())
5 .exec(
6 session-> {
7 fname1 = “Testdata/” + session.getString(“Org”) + “.csv”;
8 System.out.println("org " + fname1);
9 feed(csv(fname1));
10 String item = session.getString(“I_Item”);
11 System.out.print(“Org–>” + “item -->” + item);
12 return session;
13 }
14 );

Really, you can not use Gatling feeders this way. This is something you have to implement yourself, possibly with the same CSV parser than us: https://simpleflatmapper.org/, but not with our built-ins.

Thanks @slandelle . Will check