# Adding data in the ctx

**URL:** <https://discuss.elastic.co/t/adding-data-in-the-ctx/24680>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [July 1, 2015, 5:37am UTC](https://discuss.elastic.co/t/adding-data-in-the-ctx/24680 "2015-07-01T05:37:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gphadke](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@gphadke](https://discuss.elastic.co/u/gphadke)\
**Post date:** [July 1, 2015, 5:37am UTC](https://discuss.elastic.co/t/adding-data-in-the-ctx/24680/1 "2015-07-01T05:37:36Z")

</div>

Hello

It appears that we can store the data in the ctx.vars for the particular execution context, how do I add it? ( groovy novice). Also, will the information be stored in the watch\_history?

Please help, any pointers to script examples for watcher will also help.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [July 1, 2015, 6:31am UTC](https://discuss.elastic.co/t/adding-data-in-the-ctx/24680/2 "2015-07-01T06:31:39Z")

</div>

Any script in a watch can add variables to the context. For example something like this can be added to a script condition: `ctx.vars.my_var=5; return ctx.vars.my_var <= 5;`

Once a context variable has been defined it is accessible in all places of a Watch that supports scripting. So in the above example the `ctx.vars.my_var` can also be checked in a script transform elsewhere in the Watch.

Context variables are scoped to the watch execution to are defined in. Context variables aren't stored in the watch history. However when using the execute watch api to test/debug a watch, the context vars can be included in the response if the `debug` option is specified.

---

<div class="post-metadata">

**Author:** ![gphadke](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@gphadke](https://discuss.elastic.co/u/gphadke)\
**Post date:** [July 1, 2015, 7:03am UTC](https://discuss.elastic.co/t/adding-data-in-the-ctx/24680/3 "2015-07-01T07:03:38Z")

</div>

Thanks. I was expecting that the values get stored in the vars in watch\_history and hence was not sure.  
That helped.

---

<div class="post-metadata">

**Author:** ![gphadke](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@gphadke](https://discuss.elastic.co/u/gphadke)\
**Post date:** [July 1, 2015, 8:54am UTC](https://discuss.elastic.co/t/adding-data-in-the-ctx/24680/4 "2015-07-01T08:54:04Z")

</div>

Hello Martijn

Where do we specify the debug option?

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [July 1, 2015, 5:27pm UTC](https://discuss.elastic.co/t/adding-data-in-the-ctx/24680/5 "2015-07-01T17:27:05Z")

</div>

The execute watch rest api is described here: [https://www.elastic.co/guide/en/watcher/current/api-rest.html#api-rest-execute-watch](https://www.elastic.co/guide/en/watcher/current/api-rest.html#api-rest-execute-watch)

But the `debug` option isn't described there, but you can just append `debug=true` to the query string of the url.

---

<div class="post-metadata">

**Author:** ![gphadke](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@gphadke](https://discuss.elastic.co/u/gphadke)\
**Post date:** [July 2, 2015, 4:45am UTC](https://discuss.elastic.co/t/adding-data-in-the-ctx/24680/6 "2015-07-02T04:45:15Z")

</div>

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:49pm UTC](https://discuss.elastic.co/t/adding-data-in-the-ctx/24680/7 "2017-07-06T13:49:21Z")

</div>


