# Default value saving as result on check

**URL:** <https://community.gatling.io/t/default-value-saving-as-result-on-check/813>\
**Category:** Gatling (Open-Source)\
**Created:** [February 11, 2014, 9:39am UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813 "2014-02-11T09:39:35Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wojtek](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@Wojtek](https://community.gatling.io/u/Wojtek)\
**Post date:** [February 11, 2014, 9:39am UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/1 "2014-02-11T09:39:35Z")

</div>

Hello,

i need to parse form data and send them in next request. I wrote sth like this:

> def checkInputValue(name: String) =  
> check(regex(“”“name=”.\*“”" + name + “”“[^”]+“.+value=”([^“]+)”“”).whatever.saveAs(name))  
> .doIf(session =\> !session(name).validate[String]) {  
> session.set(name, " ")  
> }

And in main file:

> .exec(http(“display form”)  
> .get(“”“display.html”“”)  
> .checkInputValue(“var1”)  
> .checkInputValue(“var2”)  
> …  
> .checkInputValue(“varN”))  
> .exec(http(“send form”)  
> .post(“”“send.html”)  
> .param(“var1”, “${var1}”)  
> .param(“var1”, “${var2}”)  
> …  
> param(“var1”, “${varN}”)

How can I do sth like this?  
I try to use only whatever function, but where input value is not set (value tag doesn’t exists) I get an error:

> No attribute named X’ is defined

I don’t want to put doif in my scenario always after .check.

Thanks for your help,  
Wojtek

---

<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:** [February 11, 2014, 12:51pm UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/2 "2014-02-11T12:51:57Z")

</div>

Hi,

What about using the following structure :

regex(""“name=”.\*""" + name + “”"[^"]+".+value="([^"]+)""")  
.transform(\_.orElse(Some(defaultValue))).saveAs(name)

cheers  
Nicolas

---

<div class="post-metadata">

**Author:** ![Joseph\_Forsythe](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@Joseph\_Forsythe](https://community.gatling.io/u/Joseph_Forsythe)\
**Post date:** [May 27, 2014, 3:58pm UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/3 "2014-05-27T15:58:06Z")

</div>

Hello

I realize this is an older post but I was wondering if you could help me out a bit with this. I’m using jsonPath where one of the values I want to get might be null. If it is, I want to default to a String 0.00. I tried to use something similar to your example (Some(“0.00”)) but the compiler says it requires a PartialFunction. I realize this is probably a general Scala question but I can’t seem to find much helpful information

---

<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:** [May 27, 2014, 4:50pm UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/4 "2014-05-27T16:50:02Z")

</div>

Which version do you use?

---

<div class="post-metadata">

**Author:** ![Joseph\_Forsythe](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@Joseph\_Forsythe](https://community.gatling.io/u/Joseph_Forsythe)\
**Post date:** [May 27, 2014, 5:05pm UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/5 "2014-05-27T17:05:35Z")

</div>

I’m using 1.5.5

---

<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:** [May 27, 2014, 5:12pm UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/6 "2014-05-27T17:12:00Z")

</div>

So this thread was about Gatling 2.  
Sadly, you can’t achieve default values with Gatling 1 API.

---

<div class="post-metadata">

**Author:** ![Joseph\_Forsythe](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@Joseph\_Forsythe](https://community.gatling.io/u/Joseph_Forsythe)\
**Post date:** [May 27, 2014, 5:16pm UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/7 "2014-05-27T17:16:58Z")

</div>

Ah okay. Well, bummer

So, a follow up question then 😛 . Before I found this post I was trying something similar to the following:

.check(  
jsonPath("$.totals[0].tax.amount")  
.whatever  
.saveAs(“taxAmt”)  
)

And then further in the execution plan:

exec(session =\> {  
if (!session.isAttributeDefined(“taxAmt”)) {  
session.setAttribute(“taxAmt”, “0.00”)  
}  
session  
})

But when I dump the session I don’t see the taxAmt attribute. Is there a way to programmatically add session attributes besides saveAs

---

<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:** [May 27, 2014, 5:25pm UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/8 "2014-05-27T17:25:09Z")

</div>

Ah, yes, you’re right, you could do that in 2 steps!

You’re problem is that Session is immutable, as explained in the documentation, so setAttribute returns a new instance.

exec(session =\> {  
if (!session.isAttributeDefined(“taxAmt”)) {  
session.setAttribute(“taxAmt”, “0.00”)  
} else {  
session  
}  
})

---

<div class="post-metadata">

**Author:** ![Joseph\_Forsythe](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@Joseph\_Forsythe](https://community.gatling.io/u/Joseph_Forsythe)\
**Post date:** [May 27, 2014, 5:26pm UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/9 "2014-05-27T17:26:59Z")

</div>

D’oh! I forgot that it was immutable. Thanks for the help!

---

<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:** [May 27, 2014, 6:02pm UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/10 "2014-05-27T18:02:11Z")

</div>

You’re welcome!

---

<div class="post-metadata">

**Author:** ![deepshikha\_baliyan](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@deepshikha\_baliyan](https://community.gatling.io/u/deepshikha_baliyan)\
**Post date:** [July 28, 2020, 7:09am UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/11 "2020-07-28T07:09:52Z")

</div>

Hi Nicolas,

I tried using your solution and I am getting below error on this :

00:08:33.596 [ERROR] i.g.c.ZincCompiler$ - C:\Users\dball83\Downloads\gatling-charts-highcharts-bundle-3.3.1-bundle (1)\gatling-charts-highcharts-bundle-3.3.1\user-files\simulations\computerdatabase\ShopSite\_Scripts\CheckoutService.scala:76:57: **type mismatch;**  
**found : Some[String]**  
**required: PartialFunction[?,?]**  
.check(jsonPath("$.cartId").transform(\_.orElse(Some(“NOTFOUND”))).saveAs(“c\_CartId”))

Can you please take a look here

---

<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:** [July 28, 2020, 10:26am UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/12 "2020-07-28T10:26:40Z")

</div>

First, you want to use transformOption, not transform, see documentation: [https://gatling.io/docs/current/http/http\_check#transforming](https://gatling.io/docs/current/http/http_check#transforming).

Then, there’s a limitation in the checks design in Gatling 3 that forces users to have to make transform input type explicit, see [https://github.com/gatling/gatling/issues/3926](https://github.com/gatling/gatling/issues/3926). This will be fixed in Gatling 3.4.

---

<div class="post-metadata">

**Author:** ![deepshikha\_baliyan](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@deepshikha\_baliyan](https://community.gatling.io/u/deepshikha_baliyan)\
**Post date:** [August 5, 2020, 7:46pm UTC](https://community.gatling.io/t/default-value-saving-as-result-on-check/813/13 "2020-08-05T19:46:21Z")

</div>

Thanks @stephane, This is working for me
