# Watcher action: multiple actions foreach

**URL:** <https://discuss.elastic.co/t/watcher-action-multiple-actions-foreach/325817>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [February 17, 2023, 7:01am UTC](https://discuss.elastic.co/t/watcher-action-multiple-actions-foreach/325817 "2023-02-17T07:01:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mch1307](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@mch1307](https://discuss.elastic.co/u/mch1307)\
**Post date:** [February 17, 2023, 7:01am UTC](https://discuss.elastic.co/t/watcher-action-multiple-actions-foreach/325817/1 "2023-02-17T07:01:52Z")

</div>

Hi,  
I have a watcher with an aggregation query. In the action section, I am trying to execute two actions (transform, then webhook) for each element in the query response. From the logs, it seems the webhook is being executed before the transform. Is there a way to "force" sequence of actions?

```auto
"actions": {
    "log": {
      "foreach": "ctx.payload.aggregations.downservices.buckets",
      "max_iterations": 100,
      "transform": {
        "script": {
          "source": "return ['event':'HttpServiceDown', 'resource':'key[0]','service':'key[1]','severity':2,'status':'Unreachable']",
          "lang": "painless"
        }
      },
      "webhook": {
        "scheme": "https",
        "host": "somehost",
        "port": somePort,
        "method": "post",
        "path": "/some/path",
        "body": "{{#toJson}}ctx.payload{{/toJson}}"
      }
    }
  }

```

---

<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:** [March 17, 2023, 7:01am UTC](https://discuss.elastic.co/t/watcher-action-multiple-actions-foreach/325817/2 "2023-03-17T07:01:56Z")

</div>

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