# Session foreach error

**URL:** <https://community.gatling.io/t/session-foreach-error/4236>\
**Category:** Gatling (Open-Source)\
**Created:** [March 20, 2018, 6:33pm UTC](https://community.gatling.io/t/session-foreach-error/4236 "2018-03-20T18:33:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Filipski](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@Andrew\_Filipski](https://community.gatling.io/u/Andrew_Filipski)\
**Post date:** [March 20, 2018, 6:33pm UTC](https://community.gatling.io/t/session-foreach-error/4236/1 "2018-03-20T18:33:44Z")

</div>

Hey,

I have this code that the foreach can’t read from the saveAs. Any ideas?

```auto
val getExample = exec(http("")
      .get(baseUrl)
      .header()
      .header()
      .check(jsonPath("$..id").findAll.saveAs("ids")))

      .foreach("${ids}", "id") {
          exec(session => {
            println("hello")
            session
          })
      }

If I do another .exec before the foreach, I can print out the vector that I get back. It comes back as Vector(1,2,3,4). So I would expect this to print hello 4 times, expect

```

```auto
the loop breaks because it cannot find the ids.

Thank you for the help!

```

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [March 20, 2018, 8:31pm UTC](https://community.gatling.io/t/session-foreach-error/4236/2 "2018-03-20T20:31:22Z")

</div>

val users = scenario(“Users”)

.exec(http(“json”)

.get(“[https://jsonplaceholder.typicode.com/posts](https://jsonplaceholder.typicode.com/posts)”)

.check(jsonPath("$…id").findAll.saveAs(“ids”)))

.foreach("${ids}", “id”) {

exec(session =\> {

println(“hello”)

session

})

}

setUp(users.inject(atOnceUsers(1)))

works fine for me
