# Problem to use "doIf"

**URL:** https://community.gatling.io/t/problem-to-use-doif/1361
**Category:** Gatling (Open-Source)
**Created:** [September 4, 2014, 3:01pm UTC](https://community.gatling.io/t/problem-to-use-doif/1361 "2014-09-04T15:01:15Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Everton\_Lima\_Aleixo](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@Everton\_Lima\_Aleixo](https://community.gatling.io/u/Everton_Lima_Aleixo)
#### Post date: [September 4, 2014, 3:01pm UTC](https://community.gatling.io/t/problem-to-use-doif/1361/1 "2014-09-04T15:01:15Z")

</div>

Hi, I am trying to use the “doIf” feature, but it does not working.

I am using Gatling 2.0.0-RC3 version.

the error message is:

11:57:24.577 [ERROR] i.g.a.ZincCompiler$ - gatling/user-files/simulations/harpia/Startup.scala:23: value doIf is not a member of io.gatling.http.request.builder.HttpRequestWithParamsBuilder  
possible cause: maybe a semicolon is missing before `value doIf’?  
11:57:24.579 [ERROR] i.g.a.ZincCompiler$ - .doIf("${database\_name}", “${database}”) {  
11:57:24.580 [ERROR] i.g.a.ZincCompiler$ - ^  
11:57:24.616 [ERROR] i.g.a.ZincCompiler$ - one error found

My imports is:

import io.gatling.core.Predef.\_  
import io.gatling.core.session.\_  
import io.gatling.core.structure.ConditionalStatements  
import io.gatling.http.Predef.\_  
import io.gatling.http.request.StringBody  
import scala.concurrent.duration.\_  
import harpia.\_

I was missing anything??  
Since now, thanks.

---

<div class="post-metadata">

### Author: ![Pierre\_DAL-PRA](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pierre\_DAL-PRA](https://community.gatling.io/u/Pierre_DAL-PRA)
#### Post date: [September 4, 2014, 3:04pm UTC](https://community.gatling.io/t/problem-to-use-doif/1361/2 "2014-09-04T15:04:18Z")

</div>

Hi Everton,

It looks like you’re missing a right parenthensis somewhere in your scenario, as you’re seemingly trying to call _doIf_ on a _http(…)_ request instead of a _exec(…)_ block.

Cheers,

Pierre

---

<div class="post-metadata">

### Author: ![Everton\_Lima\_Aleixo](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@Everton\_Lima\_Aleixo](https://community.gatling.io/u/Everton_Lima_Aleixo)
#### Post date: [September 4, 2014, 3:25pm UTC](https://community.gatling.io/t/problem-to-use-doif/1361/3 "2014-09-04T15:25:28Z")

</div>

Sorry Pierre,  
But I think I was using the doif in the exec(…) block. My code is following:

val scn = scenario(“Insertions”) // Cria o database  
.feed(feederConfig)  
.exec(http(“createDB”)  
.post("/v1/databases")  
.body(StringBody(""""{ “database\_name”:${database} }""")).asJSON  
.check(jsonPath("$[0].database\_name").saveAs(“database\_name”))  
.doIfOrElse("${database\_name}", “${database}”) {  
println(“Database created.”)  
} {  
println(“Database already created.”)  
}  
)

I switch the doIf by a doIfOrElse.  
But the error is the same.

---

<div class="post-metadata">

### Author: ![Pierre\_DAL-PRA](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pierre\_DAL-PRA](https://community.gatling.io/u/Pierre_DAL-PRA)
#### Post date: [September 4, 2014, 3:30pm UTC](https://community.gatling.io/t/problem-to-use-doif/1361/4 "2014-09-04T15:30:00Z")

</div>

Nope :

val scn = scenario(“Insertions”) // Cria o database  
.feed(feederConfig)  
.exec(http(“createDB”)  
.post("/v1/databases")  
.body(StringBody(""""{ “database\_name”:${database} }""")).asJSON  
.check(jsonPath("$[0].database\_name").saveAs(“database\_name”))**) \<— Missing parenthesis right here: first one close saveAs(…), second one close check(…), exec wasn’t closed.**  
.doIfOrElse("${database\_name}", “${database}”) {  
println(“Database created.”)  
} {  
println(“Database already created.”)  
}  
)

---

<div class="post-metadata">

### Author: ![Everton\_Lima\_Aleixo](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@Everton\_Lima\_Aleixo](https://community.gatling.io/u/Everton_Lima_Aleixo)
#### Post date: [September 4, 2014, 3:42pm UTC](https://community.gatling.io/t/problem-to-use-doif/1361/5 "2014-09-04T15:42:21Z")

</div>

All right. But now that I put the new “)”. A new error appear:

12:38:24.267 [ERROR] i.g.a.ZincCompiler$ - gatling/user-files/simulations/harpia/Startup.scala:23: too many arguments for method doIfOrElse: (condition: io.gatling.core.session.Session =\> io.gatling.core.validation.Validation[Boolean])(thenNext: io.gatling.core.structure.ChainBuilder)(elseNext: io.gatling.core.structure.ChainBuilder)io.gatling.core.structure.ScenarioBuilder  
12:38:24.269 [ERROR] i.g.a.ZincCompiler$ - ).doIfOrElse("${database\_name}", “${database}”) {  
12:38:24.269 [ERROR] i.g.a.ZincCompiler$ - ^  
12:38:24.296 [ERROR] i.g.a.ZincCompiler$ - one error found  
Compilation failed

the new code is:  
val scn = scenario(“Insertions”) // Cria o database  
.feed(feederConfig)  
.exec(http(“createDB”)  
.post("/v1/databases")  
.body(StringBody(""""{ “database\_name”:${database} }""")).asJSON  
.check(jsonPath("$[0].database\_name").saveAs(“database\_name”))  
).doIfOrElse("${database\_name}", “${database}”) {  
exec(http(“Database created”).get("/v1/imports"))  
}  
{  
exec(http(“Database already created”).get("/v1/imports"))  
}

---

<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 4, 2014, 3:52pm UTC](https://community.gatling.io/t/problem-to-use-doif/1361/6 "2014-09-04T15:52:57Z")

</div>

Could you share your WHOLE simulation into a [GIST](https://gist.github.com), please?

---

<div class="post-metadata">

### Author: ![Everton\_Lima\_Aleixo](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@Everton\_Lima\_Aleixo](https://community.gatling.io/u/Everton_Lima_Aleixo)
#### Post date: [September 4, 2014, 5:03pm UTC](https://community.gatling.io/t/problem-to-use-doif/1361/7 "2014-09-04T17:03:04Z")

</div>

Ofcouse. That’s it:

[https://gist.github.com/anonymous/bb2b2a4a3ad87ea9c647](https://gist.github.com/anonymous/bb2b2a4a3ad87ea9c647)

Is possible instead of use “check(…)” use other form to store information in some variable to use in the “doIf”??  
Because if the “check” fail it returns an error. Like the check by status code = 201.

---

<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 4, 2014, 6:51pm UTC](https://community.gatling.io/t/problem-to-use-doif/1361/8 "2014-09-04T18:51:23Z")

</div>

In your gist, there’s a missing “)” just before your .doIfOrElse in order to close the exec for the request.  
Then, if your use doIfOrElse, you have to provide the alternative for the else. Otherwise, just use a doIf.
