# Store result from ArrayBuffer in session

**URL:** https://community.gatling.io/t/store-result-from-arraybuffer-in-session/971
**Category:** Gatling (Open-Source)
**Created:** [April 22, 2014, 9:31am UTC](https://community.gatling.io/t/store-result-from-arraybuffer-in-session/971 "2014-04-22T09:31:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![COTTET\_Julien](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@COTTET\_Julien](https://community.gatling.io/u/COTTET_Julien)
#### Post date: [April 22, 2014, 9:31am UTC](https://community.gatling.io/t/store-result-from-arraybuffer-in-session/971/1 "2014-04-22T09:31:30Z")

</div>

Il want to do something like :

.get("/rest/historisation/findUserHistory")  
.check(jsonPath("$…historique-recherche[\*].id-variante").findAll.saveAs(“IDS\_VAR\_HISTO”))  
)  
.exec(session =\> {  
session.set(“ID\_VAR”, “${IDS\_VAR\_HISTO.random}”)  
})

But when i’m accessing the value of my session variable i got : “${IDS\_VAR\_HISTO.random}”

How can i store the random result in an attribute of my session ?

I want to put the result from differents chains and not only from “IDS\_VAR\_HISTO” but from “IDS\_VAR\_HISTO”, “IDS\_VAR\_CNIT”, etc.  
This aims to get always my id from "${ID\_VAR} independently of the chain.

Thank you in advance for helping me.

---

<div class="post-metadata">

### Author: ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)
#### Post date: [April 22, 2014, 9:37am UTC](https://community.gatling.io/t/store-result-from-arraybuffer-in-session/971/2 "2014-04-22T09:37:56Z")

</div>

Which version of Gatling are you using ?

---

<div class="post-metadata">

### Author: ![COTTET\_Julien](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@COTTET\_Julien](https://community.gatling.io/u/COTTET_Julien)
#### Post date: [April 22, 2014, 11:24am UTC](https://community.gatling.io/t/store-result-from-arraybuffer-in-session/971/3 "2014-04-22T11:24:13Z")

</div>

I’m on Gatling 2.0.0-M3a

---

<div class="post-metadata">

### Author: ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)
#### Post date: [April 22, 2014, 3:28pm UTC](https://community.gatling.io/t/store-result-from-arraybuffer-in-session/971/4 "2014-04-22T15:28:43Z")

</div>

Hi,

.exec(session =\> {  
session.set(“ID\_VAR”, “${IDS\_VAR\_HISTO.random}”)  
})

The red expression is a regular String, it won’t be interpreted as an EL-Expression.  
Why do you do this in an extra step ?

If you really need to store that in the session, I would recommand to do something like that :

import java.util.concurrent.ThreadLocalRandom  
import io.gatling.core.validation.Success

.exec(http(“TODO”).get("/rest/historisation/findUserHistory")  
.check(jsonPath("$…historique-recherche[\*].id-variante").ofType[Long].findAll.saveAs(“IDS\_VAR\_HISTO”))  
)  
.exec(session =\> {  
session(“IDS\_VAR\_HISTO”).validate[Seq[Long]] match {  
case Success(ids) =\>  
val index = ThreadLocalRandom.current.nextInt(ids.size)  
session.set(“ID\_VAR”, ids(index))  
case \_ =\> session  
}  
})

Does it help ?

Regards  
Nicolas
