Trigger Settings & Conditions in Power Automate
Tags: powerautomate, powerplatform, rpa, lowcode
Published: 2023-05-10 08:02:09

Most developers have tinkered with their trigger settings, but the documentation isn't great so we often leave some powerful functionality on the table.

In this blog I wanted to look at a few standard triggers, with most of the information transferable to others (Not all triggers will have all but I have not seen any that others have that these don't have).

The triggers I am looking at are

SharePoint - When an item is created or modified
Outlook 365- When a new email arrives (V3)'
On Button Press

---

![sharepoint trigger Settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h3wh6q14hsg28vvcf2fh.png)

## 1. Split on
This is a niche case but still useful to know. Default setting on split on trigger will mean that every item created or modified will trigger its own flow run. Turning this off will mean any outstanding items will be ran in one flow (so all the trigger inputs become an array instead of a single object).
When is this useful, well for starters Power Automate may feel like it is instant, but actually it is more of regular poll (this often depends on your license as to how often). You can see the poll time if you peak the code.

![trigger code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ijqudd83s8b5njwuswv.png)
_As you can see here its every 1 minute but I have seen 15 minutes before)_

So there will be times when lots of changes, especially when you edit in grid view. Handling all changes in one flow can have its advantages, like knowing when to send a complete report.

## 2. Split-On Array
We have already shown that we can either split on row/item or return an array. What we can also do is change what we split on (in some triggers but not all). SharePoint may not offer alternatives but Outlook on Mail received does.


![outlook trigger split on](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/swk8lpt6q3d04fceb2p7.png)

As you can see, we can split on the value (email) or on attachments. Splitting on attachments could be a useful tigger, but no matter what I try I get errors.


![split on error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2b37iqkwcdk3e4jyzma.png)


![split on error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pgyswyg6eb0ix9bgajc.png)

And I think I know the issue, the split on is
```
@triggerBody()?['body/attachments'])
```
when it should be
```
@triggerBody()?['attachments'])
```
or
```
@triggerOutput()?['body/attachments'])
```
But even when I edit the trigger to the correct value (see how to here [Creating a Power Automate Flow in Code](https://dev.to/wyattdave/creating-a-power-automate-flow-in-code-29pk))

![power automate code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uefgxec9tjyieoyj4svg.png)

I now get a type error.

![type trigger error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g172rjq8gbqz8ioh8q88.png)

This looks it might have been designed for Logic Apps where the schema is different.

## 3. Split-On Tracking ID
This is a strange one, and is all due to Power Automate been built on logic apps. In logic apps you can split logging/tracking. By default it's by the same as the flow, but you can set the logs to split by nested arrays within the flow.
In other words, it's not something we can use unless we are tracking within Logic Apps. For more see here [www.atomicscope.com](https://www.atomicscope.com/blog/spliton-client-tracking-id-in-logic-apps/)

## 4. Secure Inputs and Outputs

Securing your inputs and outputs will mean all data shown in the flow logs will be encrypted.
Inputs in this case will be the site name and list id, the outputs all the rows' data.

![secure inputs and outputs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/84415zvszhc0fa3dndx6.png)

## 5. Retry

Retry is the same as any action step, with how many times you want the flow to retry.

![retry](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iy8322ygy9vekzyn6xxj.png)

**None**- no retry
**Exponential Interval** - delay in between each retry gets 2x as long up to set amount or time
![exponential interval](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gy2p4tmk8ajgcww6qeo9.png)
**Fixed Interval** - Set interval up to a set amount

_The default is an exponential interval policy set to retry 4 times_

## 5. Concurrency

Concurrency is the limit of parallel flows that can run at once. By default it is off, so in theory an infinite number of flows could run concurrently (e.g a million emails arrived on a 'email arrives trigger' would start 1 million flows simultaneously).


![concurrency control](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gtkkuocl3dgi0c9l89d1.png)

Setting to 1 would force each flow to run synchronously, this is could be important for 2 key reasons:

1. Output order, I want the outputs in same order as inputs
2. Throttling, if they all try to send an email simultaneously you might get throttled or worst (My outlook account got suspended because I tried to send 20 emails simultaneously, flagging me as sending spam)

_Note: once turned on it cannot be turned off, so the maximum would become 100_

## 7. Trigger Conditions

And this is the most powerful (and probably most known). Conditions allow us to only run if a condition is met. This is great for saving api calls and keeping your logging clean and manageable. 

We can one condition, or multiple, each is treated as an 'and'. But we can also use the 'or' expression within the trigger 

```
@or(condtion1,condition2)
```

![trigger conditions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ltqfn2q10ag5o9dc11h.png)

The above has 3 conditions

- Wasn't Modified on a specific date
- Wasn't created (only modified)
- Day triggered wasn't Sunday

You can also use trigger condition on nested arrays by either

**Referencing nth**
```
@contains(triggerOutputs()?['body/attachments'][0]['name'], 'ABC')
```

**Or for all of them using String**
```
@contains(string(triggerOutputs()?['body/attachments']), 'ABC')
```

---
As you can see there are a lot of power in using trigger settings, but also bugs/legacy Logic App inputs in the mix too that shouldn't be used.

**Further Reading**

- [MS-learn-limits-and-configs](https://learn.microsoft.com/en-us/power-automate/limits-and-config)
- [Filter-trigger-condtions](https://dev.to/wyattdave/power-automate-10-quick-developer-tips-3ik9)
- [atomicscope-split-on-client-id](https://www.atomicscope.com/blog/spliton-client-tracking-id-in-logic-apps/)
- [MS-learn-customize-trigger-conditions](https://learn.microsoft.com/en-us/power-automate/triggers-introduction#customize-a-trigger-by-adding-conditions)