# Dynamic scenario

**URL:** <https://community.gatling.io/t/dynamic-scenario/3526>\
**Category:** Gatling (Open-Source)\
**Created:** [January 27, 2017, 2:48pm UTC](https://community.gatling.io/t/dynamic-scenario/3526 "2017-01-27T14:48:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zdenek\_Farana1](https://avatars.discourse-cdn.com/v4/letter/z/5daacb/32.png) [@Zdenek\_Farana1](https://community.gatling.io/u/Zdenek_Farana1)\
**Post date:** [January 27, 2017, 2:48pm UTC](https://community.gatling.io/t/dynamic-scenario/3526/1 "2017-01-27T14:48:04Z")

</div>

Hi,

I’m building a scenario which discovers its next steps from the responses. I’m stuck at using session directly; a following is a simplified example:

`scenario("test") .exec { http("get first").get("/first").check(bodyString.transform{ bs => //json parsing using play-json, jsonPath did not seem exactly convenient for complex transformation val theMap: Map[String,Seq[String]] = ... //this is the signature I want and get theMap }.saveAs("theMap")) }.exec { session => val theMap = session("theMap").as[Map[String,Seq[String]]] val requests = theMap("second").map { id => http(s"get $id").get(s"/$id")) } http("whatever").resources(requests:_*) //yes, I really really really need to fetch all of these requests in parallel session }`

Now, what happens is that no request is emitted in the second exec; I guess it’s because I’m returning session and hence the requests are kinda side effect.

How can I achieve what I want? What am I missing here?

Thanks,

Zdenek

---

<div class="post-metadata">

**Author:** ![vu.nguyen](https://avatars.discourse-cdn.com/v4/letter/v/ba9def/32.png) [@vu.nguyen](https://community.gatling.io/u/vu.nguyen)\
**Post date:** [January 28, 2017, 4:49am UTC](https://community.gatling.io/t/dynamic-scenario/3526/2 "2017-01-28T04:49:08Z")

</div>

The warning in this section may provide some explanation:

[http://gatling.io/docs/2.2.3/general/scenario.html#exec](http://gatling.io/docs/2.2.3/general/scenario.html#exec)

---

<div class="post-metadata">

**Author:** ![Zdenek\_Farana1](https://avatars.discourse-cdn.com/v4/letter/z/5daacb/32.png) [@Zdenek\_Farana1](https://community.gatling.io/u/Zdenek_Farana1)\
**Post date:** [January 29, 2017, 8:30pm UTC](https://community.gatling.io/t/dynamic-scenario/3526/3 "2017-01-29T20:30:41Z")

</div>

I understand the explanation, but I could use some directions how to achieve what I want.

Maybe using repeat?

---

<div class="post-metadata">

**Author:** ![Zdenek\_Farana1](https://avatars.discourse-cdn.com/v4/letter/z/5daacb/32.png) [@Zdenek\_Farana1](https://community.gatling.io/u/Zdenek_Farana1)\
**Post date:** [January 29, 2017, 9:18pm UTC](https://community.gatling.io/t/dynamic-scenario/3526/4 "2017-01-29T21:18:11Z")

</div>

I just don’t understand why there is no exec which would take (Session) =\> ActionBuilder for situations when you want to do read-only ops over Session.

---

<div class="post-metadata">

**Author:** ![Stephen](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@Stephen](https://community.gatling.io/u/Stephen)\
**Post date:** [January 30, 2017, 11:26am UTC](https://community.gatling.io/t/dynamic-scenario/3526/5 "2017-01-30T11:26:35Z")

</div>

Hello,

I’m not quite sure about my idea, I haven’t much time to test it but maybe you could try creating this method to generate your HttpRequestBuilder with resources:

`

```auto
def generateResources(request: HttpRequestBuilder) = {
  var requests = _
  exec { session =>

  val theMap = session("theMap").as[Map[String,Seq[String]]]
  requests = theMap("second").map { id =>
    http(s"get $id").get(s"/$id")
  }
  session
}
request.resources(requests)
}

```

`

And use it in the scenario like this :

`exec(generateResources(http("whatever")))`

Hope it could help
