# type mismatch error is shown while passing “tName” in stringbody

**URL:** <https://community.gatling.io/t/type-mismatch-error-is-shown-while-passing-tname-in-stringbody/3543>\
**Category:** Gatling (Open-Source)\
**Created:** [February 8, 2017, 2:09pm UTC](https://community.gatling.io/t/type-mismatch-error-is-shown-while-passing-tname-in-stringbody/3543 "2017-02-08T14:09:59Z")\
**Posts on this page:** 3\
**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:** [February 8, 2017, 2:09pm UTC](https://community.gatling.io/t/type-mismatch-error-is-shown-while-passing-tname-in-stringbody/3543/1 "2017-02-08T14:09:59Z")

</div>

```auto
val tName = System.getProperty("tName", "asdflkjh")

```

I am planning to make `"tName"` dynamic but it prints `"$tName"` in output instead of “asdflkjh”.`.body(StringBody("""{"objectId":${assetid},"objectType":"m-asset","name1": "$tName","accountId":4,"userId":5}"""))`

If I use `'session=>s'` in stringBody it throws below error `.body(StringBody(session=>s"""{"objectId":${assetid},"objectType":"m-asset","name1": "$tName","accountId":4,"userId":5}"""))`

**//////////////////////ERROR: ////////////////////////////////**

```auto
3894 [main] ERROR io.gatling.compiler.ZincCompiler$ - type mismatch;
 found : String("${ThumbIdList}")
 required: ?{def apply: ?}
Note that implicit conversions are not applicable because they are ambiguous:
 both method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps
 and method stringToExpression in object Predef of type [T](string: String)(implicit evidence$1: scala.reflect.ClassTag[T])io.gatling.core.session.Expression[T]
 are possible conversion functions from String("${ThumbIdList}") to ?{def apply: ?}
3894 [main] ERROR io.gatling.compiler.ZincCompiler$ - .foreach("${ThumbIdList}", "thumbid") {
3894 [main] ERROR io.gatling.compiler.ZincCompiler$ - ^
3914 [main] ERROR io.gatling.compiler.ZincCompiler$ - D:\myTags.scala:110: type mismatch;
 found : String("thumbid")
 required: ?{def apply: ?}
Note that implicit conversions are not applicable because they are ambiguous:
 both method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps
 and method stringToExpression in object Predef of type [T](string: String)(implicit evidence$1: scala.reflect.ClassTag[T])io.gatling.core.session.Expression[T]
 are possible conversion functions from String("thumbid") to ?{def apply: ?}
3914 [main] ERROR io.gatling.compiler.ZincCompiler$ - .foreach("${ThumbIdList}", "thumbid") {
3924 [main] ERROR io.gatling.compiler.ZincCompiler$ - ^
4004 [main] ERROR io.gatling.compiler.ZincCompiler$ - D:\myTags.scala:98: not found: value assetid
4004 [main] ERROR io.gatling.compiler.ZincCompiler$ - .body(StringBody(session=>s"""{"objectId":${assetid},"objectType":"m-asset","name1": "$tName","accountId":4,"userId":5}"""))
4004 [main] ERROR io.gatling.compiler.ZincCompiler$ - ^
4054 [main] ERROR io.gatling.compiler.ZincCompiler$ - three errors found
4054 [main] DEBUG io.gatling.compiler.ZincCompiler$ - Compilation failed (CompilerInterface)

```

**///////////// Script Starts here ///////////**

```auto
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class myTags extends Simulation {

    val testServerUrl = System.getProperty("testServerUrl", "https:someurl")
    val username = System.getProperty("username", "ma")
    val password = System.getProperty("password", "ma")
    val userCount = Integer.getInteger("userCount", 1).toInt
    val accountname = System.getProperty("accountname", "ma1")
    val tName = System.getProperty("tName", "asdflkjh")

    val httpProtocol = http
        .baseURL(testServerUrl)

    val headers_6 = Map(
        "Accept" -> "application/json, text/plain, */*",
        "Cache-Control" -> "no-cache",
        "If-Modified-Since" -> "Mon, 26 Jul 1997 05:00:00 GMT",
        "Pragma" -> "no-cache",
        "X-Requested-With" -> "XMLHttpRequest")

    val headers_52 = Map(
        "Accept" -> "application/json, text/plain, */*",
        "Accept-Encoding" -> "gzip, deflate, br",
        "Cache-Control" -> "no-cache",
        "Origin" -> testServerUrl,
        "Pragma" -> "no-cache",
        "X-Requested-With" -> "XMLHttpRequest",
        "Content-Type" -> "application/json;charset=UTF-8",
        "Connection" -> "keep-alive",
        "User-Agent" -> "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36")

    val scn = scenario("Add")
        .exec(http("Fetch")
            .get("/someurl2")
            .headers(headers_6)
            .check(jsonPath("$.resources[*].ids").findAll.saveAs("IdList"))
            .check(jsonPath("$.resources[*].thumbIds").findAll.saveAs("ThumbIdList")))

        .foreach("${IdList}", "assetid") {
            exec(http("Load_Details")
            .get("/mmm/images/loader.svg")
            .resources(
            http("C1_request")
            .get("/mmm/ast/${assetid}/c1")
            .headers(headers_6),
            http("T1_request")
            .get("/mmm/ast/${assetid}/t1")
            .headers(headers_6),
            http("A1_request")
            .post("/mmm/actions")
            .headers(headers_52)
            .body(StringBody("""{"objects":[{"id":${assetid},"resource":"m-asset"}]}""")),
            http("R1_request")
            .get("/mmm/variants%3BresourceType=m-asset")
            .headers(headers_6),
            http("S1_request")
            .get("/mmm/ast/${assetid}/keyframes")
            .headers(headers_6)))

        .exec(http("Add Tags")
            .post("/mmm/objs/${assetid}/tags")
            .headers(headers_52)

            // The PROBLEM IS Here. I want to pass "$tName" dynamically
            .body(StringBody("""{"objectId":${assetid},"objectType":"m-asset","name1": "$tName","accountId":4,"userId":5}"""))
            )   
        }

        .foreach("${ThumbIdList}", "thumbid") {
            doIf(session => session("thumbid").as[String] != "-1")
            {
                exec(http("Set_Keyframes")
                .get("/mmm/keyframes/${thumbid};width=185;height=103")
                )
            }
        }

    setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)
}

```

---

<div class="post-metadata">

**Author:** ![notdryft](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/notdryft/32/1103_2.png) [@notdryft](https://community.gatling.io/u/notdryft)\
**Post date:** [February 8, 2017, 2:39pm UTC](https://community.gatling.io/t/type-mismatch-error-is-shown-while-passing-tname-in-stringbody/3543/2 "2017-02-08T14:39:21Z")

</div>

You have a conflict between Gatling’s Expression Language (used with a ${}), and Scala’s String Interpolation (also ${} and $, completed with the s"" macro).

There is a way to use both, but this is a bit tricky:

- Prefix the string with s
- Escape Gatling’s Expression Language such that it won’t be interpreted by Scala as an interpolation  
Typically, double the $ that are Gatling’s EL you don’t want to be interpolated, as such:

```auto
StringBody(s"""{"objectId":$${assetid},"objectType":"m-asset","name1": "$tName","accountId":4,"userId":5}""")

```

---

<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:** [February 9, 2017, 5:05am UTC](https://community.gatling.io/t/type-mismatch-error-is-shown-while-passing-tname-in-stringbody/3543/3 "2017-02-09T05:05:04Z")

</div>

**Thanks a TON Guillaume Corré** for such a nice explanation. It worked. Thanks 🙂
