# Can't Access a Watcher Payload Object in Action Condition

**URL:** <https://discuss.elastic.co/t/cant-access-a-watcher-payload-object-in-action-condition/261022>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [January 13, 2021, 4:22pm UTC](https://discuss.elastic.co/t/cant-access-a-watcher-payload-object-in-action-condition/261022 "2021-01-13T16:22:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![esguy](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@esguy](https://discuss.elastic.co/u/esguy)\
**Post date:** [January 13, 2021, 4:22pm UTC](https://discuss.elastic.co/t/cant-access-a-watcher-payload-object-in-action-condition/261022/1 "2021-01-13T16:22:24Z")

</div>

I'm attempting to set up a condition for an action using an attribute of the current watch payload. The watch payload is defined as the following in a script transform:

```auto
return [
              'table': lessRows.stream().map(x -> {return [
                'table_name': x[0],
                'schema_name': x[1],
                'db_name': x[2],
                'cluster_name': x[3],
                'new_row_count': x[4],
                'old_row_count': x[5],
                'diff': x[6],
                'percent_change': x[7],
                'size': tableSize]}).collect(Collectors.toList())
            ]

```

where `lessRows` is a list object containing output information.

I'm trying to write a condition for an action to check if `tableSize > 0`. I've tried the following:

```auto
"condition": {
        "compare": {
          "ctx.payload.table.size": {
            "gt": 0
          }
        }
      }

```

```auto
"condition": {
        "script": {
          "source": "return ctx.payload.table.size > 0"
        }
      }

```

```auto
"condition": {
        "script": {
          "source": "return ctx.payload.table.stream().anyMatch(x -> x.size > 0)"
        }
      }

```

None have worked and I'm really not sure why. `tableSize` is declared as an `int` in the script transform so type shouldn't be an issue. And I am sure that `tableSize` is incremented accurately because when I output the `ctx.payload.table` object I get something like:

```auto
{0={cluster_name= anly_prod, new_row_count=18209133, db_name= anly_prod_db , size=1, diff=220972, schema_name= anly_prod , table_name=rtap_agg_pacing_health , percent_change=1.19, old_row_count=18430105}}

```

depending on what my input is.

So, any ideas as to why I can't compare the `ctx.payload.table.size` attribute would be very helpful. Thanks.

EDIT: Also tried:

```auto
"condition": {
    "script": {
      "source": "return ctx.payload.table.stream().anyMatch(x -> x.cluster_name.equals('anly_prod'))"
    }
  },

```

which did not work either, so I'm guessing it doesn't have to do with the `tableSize` variable.

---

<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:** [February 10, 2021, 4:22pm UTC](https://discuss.elastic.co/t/cant-access-a-watcher-payload-object-in-action-condition/261022/2 "2021-02-10T16:22:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
