# Struggling with proper way to println and get/set session vars inside repeat loop

**URL:** <https://community.gatling.io/t/struggling-with-proper-way-to-println-and-get-set-session-vars-inside-repeat-loop/1469>\
**Category:** Gatling (Open-Source)\
**Created:** [September 26, 2014, 5:17am UTC](https://community.gatling.io/t/struggling-with-proper-way-to-println-and-get-set-session-vars-inside-repeat-loop/1469 "2014-09-26T05:17:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Galen\_Fisher](https://avatars.discourse-cdn.com/v4/letter/g/dc4da7/32.png) [@Galen\_Fisher](https://community.gatling.io/u/Galen_Fisher)\
**Post date:** [September 26, 2014, 5:17am UTC](https://community.gatling.io/t/struggling-with-proper-way-to-println-and-get-set-session-vars-inside-repeat-loop/1469/1 "2014-09-26T05:17:35Z")

</div>

I have a few questions based on the following code. I’m trying to repeat creating new users multiple times serially and create a 6 digit identity number each time. I’m attempting to pad the repeat index number with this, otherwise once it gets over 9 the creation process fails since it’s adding too many digits. I may not be doing that right, but I think I’m on the right track with that. I’m using gatling 2.0 m4 I believe.

val CreateNewUserScenario = scenario(“Create New Users”)  
.repeat(3, “n”) {  
exec(session =\> {  
var intN: java.lang.Integer = Integer.parseInt(session(“n”).as[String])  
var identSuffix = String.format("%03d", intN)  
session.set(“identSuffix”, identSuffix)

println(“session follows”)  
println(session)

// return the original session  
session  
})

exec(http(“CNU\_get\_ext\_home”)  
.get("""/external/"""))  
.pause(4)  
.exec(http(“CNU\_get\_create\_acct”)  
.get("""/external/createAccount"""))  
.pause(10)  
.exec(http(“CNU\_save\_user”)  
.post("""/external/user/saveSelf""")  
.formParam(""“user\_company\_ident”"", “”“123${identSuffix}”"")  
.check(regex(""“User Account Created”"").exists))  
}

Questions are…

1. I get the following error with the above “\> No attribute named ‘identSuffix’ is defined 3 (100.0%)” How do I set this session var in the repeat loop so it’s available later in my http calls?

2. I never see the println output despite setting the logback to DEBUG once and INFO another time. How do I use println within a scenario to output the session? I attempted to follow the example from the guide but I’m not seeing anything.

3. Should I have the execs inside the repeat as two separate exec statements or is there some way to get these to work fluently? I tried adding a . in front of the second exec block but it threw errors.

Thanks!

- Galen Fisher

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [September 26, 2014, 5:46am UTC](https://community.gatling.io/t/struggling-with-proper-way-to-println-and-get-set-session-vars-inside-repeat-loop/1469/2 "2014-09-26T05:46:47Z")

</div>

Session is immutable!!!  
[http://gatling.io/docs/2.0.0-RC5/session/session\_api.html#setting-attributes](http://gatling.io/docs/2.0.0-RC5/session/session_api.html#setting-attributes)

---

<div class="post-metadata">

**Author:** ![Galen\_Fisher](https://avatars.discourse-cdn.com/v4/letter/g/dc4da7/32.png) [@Galen\_Fisher](https://community.gatling.io/u/Galen_Fisher)\
**Post date:** [September 26, 2014, 6:11am UTC](https://community.gatling.io/t/struggling-with-proper-way-to-println-and-get-set-session-vars-inside-repeat-loop/1469/3 "2014-09-26T06:11:43Z")

</div>

Thanks, my mistake. That just wasn’t getting through my head earlier.

I got it working(I think, it’s not failing anymore) by doing this:

val CreateNewUserScenario = scenario(“Create New Users”)  
.repeat(3, “n”) {  
exec(session =\> {  
var intN: java.lang.Integer = Integer.parseInt(session(“n”).as[Int].toString())  
var identSuffix = String.format("%03d", intN)

// return the original session  
session.set(“identSuffix”, identSuffix)  
})

.exec(http(“CNU\_get\_ext\_home”)  
.get("""/external/"""))  
.pause(4)  
.exec(http(“CNU\_get\_create\_acct”)  
.get("""/external/createAccount"""))  
.pause(10)  
.exec(http(“CNU\_save\_user”)  
.post("""/external/user/saveSelf""")  
.formParam(""“user\_company\_ident”"", “”“123${identSuffix}”"")  
.check(regex(""“User Account Created”"").exists))  
}

What would you recommend for checking the values of session for debugging after setting values as best practice? Something like this?

exec(session =\> {  
var intN: java.lang.Integer = Integer.parseInt(session(“n”).as[Int].toString())  
var identSuffix = String.format("%03d", intN)

// return the original session  
session.set(“identSuffix”, identSuffix)  
})

.exec(session =\> {

println(“session follows”)  
println(session)

session  
})

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [September 26, 2014, 7:41am UTC](https://community.gatling.io/t/struggling-with-proper-way-to-println-and-get-set-session-vars-inside-repeat-loop/1469/4 "2014-09-26T07:41:10Z")

</div>

Yep, that’s what I usually do.
