# Complex comparison to construct url

**URL:** <https://community.gatling.io/t/complex-comparison-to-construct-url/6056>\
**Category:** Gatling (Open-Source)\
**Created:** [April 14, 2021, 1:55am UTC](https://community.gatling.io/t/complex-comparison-to-construct-url/6056 "2021-04-14T01:55:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhang\_Chen](https://avatars.discourse-cdn.com/v4/letter/z/8491ac/32.png) [@Zhang\_Chen](https://community.gatling.io/u/Zhang_Chen)\
**Post date:** [April 14, 2021, 1:55am UTC](https://community.gatling.io/t/complex-comparison-to-construct-url/6056/1 "2021-04-14T01:55:38Z")

</div>

Hi,

I appreciate if I can get some help on this. I need to save the response from 2 requests to construct for the 3rd request, there needs to be some comparisons to figure out the correct value to use for the 3rd request url.

Here is a simplified version of the problem:

exec(  
http(“Request 1”)  
.post("/search/")  
.check(regex(“A”).find(0).saveAs(“key1”))  
.check(regex(“A”).find(0).saveAs(“key2”))  
.check(regex(“A”).find(0).saveAs(“key3”))  
.check(regex(“B”).find(0).saveAs(“value1”))  
.check(regex(“B”).find(0).saveAs(“value2”))  
.check(regex(“B”).find(0).saveAs(“value3”))  
))

exec(  
http(“Request 2”)  
.post("/search/")  
.check(regex(“A”).find(0).saveAs(“key4”))  
.check(regex(“A”).find(0).saveAs(“key5”))  
.check(regex(“A”).find(0).saveAs(“key6”))  
.check(regex(“C”).find(0).saveAs(“value4”))  
.check(regex(“C”).find(0).saveAs(“value5”))  
.check(regex(“C”).find(0).saveAs(“value6”))  
))

Now I need to compare for example if key1 is equal to key5, the I will need to use value1 and value5 to construct the 3rd request url. What is the best way to do this comparisons in gatling?

Essentially, if I were to use java, this is like two maps (in sudo code)  
map1 = {key1-\>value1, key2-\>value2, key3-\>value3}  
map2 = {key4-\>value4, key5-\>value5, key6-\>value6)

to compare the key in map1 to key in map2, if they are equal, the use the value in map1 and value in map2 to construct a url. I know how to do this in java, but i can’t figure out how to write this in gatling, apricate any help or pointers.

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [April 14, 2021, 7:26am UTC](https://community.gatling.io/t/complex-comparison-to-construct-url/6056/2 "2021-04-14T07:26:11Z")

</div>

Hi,

I’m not sure what you want to achieve.  
But you definitely should look for [Session API](https://gatling.io/docs/current/session/session_api/) to be able to save values from one request to another (you already use part of it with your `saveAs`)  
Then, a

```auto
  exec { session =>
    if(session("key1").as[String] == session("key5").as[String]) {
      session.set("toUse1", session("value1").as[String]).set("toUse2", session("value2").as[String]) 
    } else ???
  }

```

Then you will be able to use the two session variables `toUse1` and `toUse2`.

Hope it helps.

Cheers!
