title: How to execute Scenarios in Sequence in Gatling?
body: <p>I have <strong>two scenarios</strong> <strong>1st "getAssets" scenario</strong> will fetch all asset IDs and save it in a list, <strong>2nd scenario "fetchMetadata"</strong> will iterate those IDs.</p>
  
  <p>I have to execute "getAssets" scenario <strong>only once</strong> to fetch all the IDs, and "fetchMetadata" scenario till given time duration <strong>only after completion of 1st scenario</strong>.</p>
  
  <p>How can I execute both scenarios in Chain (<strong>Sequentially</strong>)?</p>
  
  <p><strong>Here is the code but it doesn't execute scenarios in sequence.</strong></p>
  
  <pre><code>import java.util.concurrent.ThreadLocalRandom
  import scala.concurrent.duration._
  import io.gatling.core.Predef._
  import io.gatling.http.Predef._
  
  class getAssetsMetadata extends Simulation {
      val getAssetURL = System.getProperty("getAssetURL", "https://performancetesting.net")
      val username = System.getProperty("username", "performanceuser")
      val password = System.getProperty("password", "performanceuser")
      val limit = Integer.getInteger("limit", 1000).toInt
      val userCount = Integer.getInteger("userCount", 100).toInt
      val duration = Integer.getInteger("duration",1).toInt //in minutes
  
      var IdList: Seq[String] = _   
  
      val httpProtocol = http
          .basicAuth(username, password)
          .baseURL(getAssetURL)
          .contentTypeHeader("""application/vnd.v1+json""")
  
      def getAssets = exec(http("List of Assets")
              .get(s"""/api/assets;limit=$limit""")
              .check(jsonPath("$.assets[*].id").findAll.transform {v =&gt; IdList = v; v }.saveAs("IdList"))
              )
  
      def fetchMetadata = exec(_.set("IdList", IdList))
          .exec(http("Metadata Request")
              .get("""/api/assets/${IdList.random()}/metadata""")
              )
  
      // Chain scenarios      
      var scn1 = scenario("Scenario 1")
              .exec(getAssets)
      var scn2 = scenario("Scenario 2")       
              .exec(fetchMetadata)
      setUp(scn1.inject(atOnceUsers(1)), scn2.inject(constantUsersPerSec(userCount) during(duration minutes))).protocols(httpProtocol)
      }
  </code></pre>