# How to Extract vector in session?

**URL:** <https://community.gatling.io/t/how-to-extract-vector-in-session/3639>\
**Category:** Gatling (Open-Source)\
**Created:** [March 28, 2017, 3:31pm UTC](https://community.gatling.io/t/how-to-extract-vector-in-session/3639 "2017-03-28T15:31:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Peter](https://community.gatling.io/u/Peter)\
**Post date:** [March 28, 2017, 3:31pm UTC](https://community.gatling.io/t/how-to-extract-vector-in-session/3639/1 "2017-03-28T15:31:08Z")

</div>

Hi,

I have saved vector in session and I want to use random value from the vector but dont know how to extract value in session.

**Errors:**  
1.  
`'httpRequest-6' failed to execute: Vector(437420, 443940, 443932, 437437, 443981, 443956, 443973, 443915, 437445) named 'termIds' does not support .random function`

And

**2. In 2nd scenario It passes vector in get request like this way,**  
  
 **`http://someurl/api/thr/Vector(435854)/terms/Vector(437420, 443940, 443932, 437437, 443981, 443956, 443973, 443915, 437445)`**

**instead of using**  
**[http://someurl/api/thr/435854/terms/443973](http://someurl/api/thr/435854/terms/443973)**

**::Here is my script::**

`  
class getTerm extends Simulation {

val repeatCount = Integer.getInteger(“repeatCount”, 1).toInt  
val userCount = Integer.getInteger(“userCount”, 1).toInt  
val turl = System.getProperty(“turl”, “some url”)

val httpProtocol = http  
.baseURL(“http://” + turl)

val headers\_10 = Map(“Content-Type” → “”“application/json”"")

var thrIds = “”  
var termIds = “”

// Scenario - 1  
val getTerms = scenario(“Scn 1”)  
.exec(http(“list\_of\_term”)  
.get("/api/abc")  
.headers(headers\_10)  
.check(jsonPath("$[\*].id")  
.findAll.saveAs(“thrIds”))  
)

.exec(http(“get\_all\_terms”)  
.get("""/api/thr/${thrIds.random()}/terms""")  
.headers(headers\_10)  
.check(jsonPath("$[\*].id")  
.findAll.saveAs(“termIds”))  
)

.exec(session =\> {  
thrIds = session(“thrIds”).as[Long].toString  
termIds = session(“termIds”).as[Long].toString  
println(“_**")  
println("Session ====\>\>\>\> " + session)  
println("Ths ID ====\>\>\>\> " + thrIds)  
println("Term ID ====\>\>\>\> " + termIds)  
println("**_”)  
session}  
)

// Scenario - 2  
val getKnownTerms = scenario(“Get Known Term”)  
.exec(_.set(“thrIds”, thrIds))  
.exec(_.set(“termIds”, termIds))

.repeat (repeatCount){  
exec(http(“get\_k\_term”)  
.get("""/api/thr/${thrIds}/terms/${termIds.random()}""")  
.headers(headers\_10))  
}

val scn = List(getTerms.inject(atOnceUsers(1)), getKnownTerms.inject(nothingFor(20 seconds), atOnceUsers(userCount)))  
setUp(scn).protocols(httpProtocol)

}  
`

---

<div class="post-metadata">

**Author:** ![Nikolay\_Degkin](https://avatars.discourse-cdn.com/v4/letter/n/a6a055/32.png) [@Nikolay\_Degkin](https://community.gatling.io/u/Nikolay_Degkin)\
**Post date:** [April 4, 2017, 12:57pm UTC](https://community.gatling.io/t/how-to-extract-vector-in-session/3639/2 "2017-04-04T12:57:53Z")

</div>

Hi Peter,  
you can try

`.exec(http("Random item") .get("api/thr/" + "${thrIds.random()}" + "/terms") )`
