# 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:** 1\
**Showing post:** 2

<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.

---

_[View the full topic](https://discuss.elastic.co/t/adding-data-in-the-ctx/24680)._
