# exec Chainbuilder and Expression function difference

**URL:** <https://community.gatling.io/t/exec-chainbuilder-and-expression-function-difference/4494>\
**Category:** Gatling (Open-Source)\
**Created:** [September 11, 2018, 11:54am UTC](https://community.gatling.io/t/exec-chainbuilder-and-expression-function-difference/4494 "2018-09-11T11:54:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthias\_Schmidt](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Matthias\_Schmidt](https://community.gatling.io/u/Matthias_Schmidt)\
**Post date:** [September 11, 2018, 11:54am UTC](https://community.gatling.io/t/exec-chainbuilder-and-expression-function-difference/4494/1 "2018-09-11T11:54:50Z")

</div>

I have a scenario with three basic exec steps:

- Add some stuff to the session
- Post some data
- get some data for verification

Running code similar to this:

`1 val simpleScenario = scenario("DEA Promotions Extended") 2 .feed(ssv(getFilename()).circular) 3 .exec{session => 4 session.set("x", "y") 5 } 6 .exec(CreatePromotion.postForStage(this.stage)) // produces: "Write DEA Promotion permission" 7 .exec{ 8 http("Lookup detailed DEA Promotion permission") 9 .get(...) 10 .headers(...) 11 .check(status.is(200)) 12 13 }`

I’ve got my two operations neatly shown in the overview while the scenario runs:

---

<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:** [September 11, 2018, 11:58am UTC](https://community.gatling.io/t/exec-chainbuilder-and-expression-function-difference/4494/2 "2018-09-11T11:58:31Z")

</div>

[https://gatling.io/docs/current/general/scenario/#exec](https://gatling.io/docs/current/general/scenario/#exec)

Warning

Gatling DSL components are immutable `ActionBuilder`(s) that have to be chained altogether and are only built once on startup. The results is a workflow chain of `Action`(s). These builders don’t do anything by themselves, they don’t trigger any side effect, they are just definitions. **As a result, creating such DSL components at runtime in functions is completely meaningless.** If you want conditional paths in your execution flow, use the proper DSL components (`doIf`, `randomSwitch`, etc)

---

<div class="post-metadata">

**Author:** ![Matthias\_Schmidt](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Matthias\_Schmidt](https://community.gatling.io/u/Matthias_Schmidt)\
**Post date:** [September 11, 2018, 12:41pm UTC](https://community.gatling.io/t/exec-chainbuilder-and-expression-function-difference/4494/3 "2018-09-11T12:41:53Z")

</div>

Hi Stéphane,

I’ve read this paragraph many times, but still don’t understand how this relates to the issue i’m facing at the moment.

The ability to pass-through the session is mentioned above the passage you refering to:

[https://gatling.io/docs/2.3/general/scenario/#exec](https://gatling.io/docs/2.3/general/scenario/#exec)

So what am i doing wrong here?

salut,

Matthias

---

<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:** [September 11, 2018, 1:01pm UTC](https://community.gatling.io/t/exec-chainbuilder-and-expression-function-difference/4494/4 "2018-09-11T13:01:19Z")

</div>

7 .exec{ session =\>  
8 http(“Lookup detailed DEA Promotion permission”)

You’re exactly doing what is described as not working. You can’t create http request inside session functions.

---

<div class="post-metadata">

**Author:** ![Matthias\_Schmidt](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Matthias\_Schmidt](https://community.gatling.io/u/Matthias_Schmidt)\
**Post date:** [September 11, 2018, 1:44pm UTC](https://community.gatling.io/t/exec-chainbuilder-and-expression-function-difference/4494/5 "2018-09-11T13:44:06Z")

</div>

Thanks for clarifying this!

I was mislead by the fact that the http call was actually running …

It might be a good idea to mention this in the exec documentation example as something which won’t work.

So how am i supposed to get a reference to the session in an followup step?

---

<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:** [September 11, 2018, 2:11pm UTC](https://community.gatling.io/t/exec-chainbuilder-and-expression-function-difference/4494/6 "2018-09-11T14:11:58Z")

</div>

> I was mislead by the fact that the http call was actually running ...

The builder gets instanciated, but no HTTP request is actually sent.

> It might be a good idea to mention this in the exec documentation example  
> as something which won't work.

It's already mentioned in this very same page:

exec { session =\>

&nbsp;&nbsp;if (someSessionBasedCondition(session)) {  
&nbsp;&nbsp;&nbsp;&nbsp;// just create a builder that is immediately discarded, hence  
doesn't do anything  
&nbsp;&nbsp;&nbsp;&nbsp;// you should be using a doIf here  
&nbsp;&nbsp;&nbsp;&nbsp;http("Get Homepage").get("[http://github.com/gatling/gatling&quot;\](http://github.com/gatling/gatling&quot;%5C))  
&nbsp;&nbsp;}  
&nbsp;&nbsp;session}
