ChainBuilder with data passing

Hi there, I have a question as below, suppose that I have 3 files as this (shortened), object name same as file name.

     session => 
         val restID = session.set("val1", theValue)


       //the body


val FirstScenarioScn = scenario("Phase_2_APIs").tryMax(3) {



What I am looking for now, is to take the restID from file1 to pass into file2, I have made both files to action under ChainBuilder, but somehow file2 does not recognize that variable, what is the exact way that I should do for this situation ?

Hi @trinp,

Documentation to manage session attributes: Gatling - Session API

So, in your file2.scala:

       //the body

val1 is the name of your session attribute in your file1.scala


hi @sbrevet , thanks for your support, after I updated my script as this.
for file1.scala

object obj1{

  def method1(): ChainBuilder = { 
    session => 
      val payloadPaymentFinalizerString = session.set("var1",val1)
      val thePayload = session.set("var2",value2)

then file2.scala

object obj2{
  def method2(): ChainBuilder = {

  val theMessage = (session: io.gatling.core.session.Session) => { 
    val payload_value = session("#{var1}").as[String]

        param1 = Option(Type(payload_value))

What I’m trying to achieve here, is to pass the var2’s value2 into payload_value, but it seems that Gatling cannot read this, so How do I extract the data in this situation ?

Hi @trinp,

It becomes harder to read the fake sample…

I will still try to help you and here, what I decoded:

As stated in the documentation:

Session instances are immutable, meaning that methods such as set return a new instance and leave the original instance unmodified!

(from Session API - Setting attributes alert tip)

So, in your method1 you only returned thePayload that only change the original session with var2. var1 is lost.

If scala is the issue, consider using our Java API.
And you should go through our tutorial and academy.


1 Like

hi @sbrevet, I see your point and understand what I did wrong there, thanks for your support, I will look through the academic course.

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