5 Quick Fixes for Power Automate
Tags: powerautomate, powerplatform, lowcode, rpa
Published: 2024-06-17 05:52:05

No matter how much I love Power Automate there are always going to be 'niggles'. I'm not talking about big issues, more the ones that you deal with as the impact isn't big enough to impact your delivery, but still big enough that you feel it.

So here are a mix of bugs and poor design decisions that I would love to see fixed.

The Changes
1 Conditions Don't Show Inputs
2 Connection Naming
3 Cancelled Runs Don't Show Logs

The Fixes
4 Switch Copy Paste
5 Expressions, Arrays and Apply to Each

---

## 1. Conditions Don't Show Inputs
Every developer must have felt the pain on this one at least once. Your flow doesn't run as expected, you check the logs and the condition returned false instead of the expected true. You look at the inputs and you see this:

![condition response](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5kejbbqc9zh27ttgdjcs.png)

Well gee that's useful, thank you. So now you have to add a compose with a list of the inputs and rerun.

The fix is easy, show the expression with the inputs, or allow an option to show values. This is kind of what I expected 'Tracked Properties' to be instead of the current implementation.

![tracked properties](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w9tijcs6eojiqx47b8l1.png)

## 2. Connection Naming
I don't know how, I always try not too, but I always end up with multiple connections for same connection. Why do I need the ability to create multiple, that's a good question.

So when I go to add a connection I end up seeing this:

![select connections](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjhb6iqrossfbn78g4vz.png)

And I have no idea which one to pick, which one is being used for what flow.

2 possible fixes, remove the ability to have more then one connection. The only reason to is to enable changing selected flow connections, and that's what connection references are for now. But if you really want to keep them then add the option to change the name in connection settings.

![connection name settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5w1va60ssxxxoks8idh1.png)

## 3. Cancelled Loop Runs Don't Show Logs
We have all probably had this happen to use, the flow is looping over hundreds of records, but it fails on the first item. You don't want to wait for the flow to finish (as that will take ages), so you cancel the run. But when you look at the logs you can't see the item that failed.

![loop cancelled](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99zwi3l69bmi7p6khdrc.png)

I understand why, as the Apply to Each is actually a API call (like Get Items from SharePoint), so the actual looping isn't done in the flow. But that said we get the item detail when complete, so why can't they return the rows that had complete when cancelled.

And that's the fix, update the Apply to Each (and Do until) API's to return items already processed when the flow is cancelled. Or the better approach return each item as it is processed, so we get to see the action in real time as the flow runs 😎

## 4. Switch Copy Paste
Now this is a niche one I admit, not many people use Switch's, and when they do they may not copy and paste that often. But if you try to you will see that there is a bug, and you can't. You can copy and paste an item from outside into the Switch, and from inside the Switch to outside, but not from inside to inside.

Don't believe me, try it. So now every time I want to duplicate an action between Switch branches I have to paste it outside the scope and drag it in.

The fix is simple, make it work. And I can even tell Microsoft why. When they last updated the schema they didn't update the Switch. 

During that update they added a operationMetadataId key to all the actions JSON's (you can see it in the peak code). But when you create a action within a scope that key isn't there.

Outside Switch
![code out of scope](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ia2tlfai64ar6t39xarg.png)

Inside Switch
![code in scope](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vyfyfwz4dku5tpgjza12.png)

## 5. Expressions and Arrays
To help you Power Automate automatically creates a 'Apply to Each' and adds the action you are editing into it if the input is a item from array. This is a nice touch and definitely stops issues for new developers. The issue I have is this behaviour also happens in the expression editor.

So lets say I want to check if the first item in an array is a value, something like:

```
if(equals(outputs('Get_items')?['body/value'][0]?['Title'],'David'),'Match','Mismatch')
```

I type:
```
if(equals(
```

and then when I select Title (or any field) it adds the action to a Apply to Each, wipes my expression and replaces it with:
```
items('For_each')?['Title']
```

![force loop](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g5r10ne386vhb3bt0fln.gif)

This is so frustrating, when I'm in the expression editor and have written an expression why does it act like I just selected it in Dynamic Content selector.

And just to add make it even more annoying it then ofen registers the action as has an array item, even when it doesn't. So you can't move it out of the loop.

![can't move empty action](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fc428plk8xuofgkix2u1.png)

The fix again is easy, if I select within the Dynamic Content selector then please do put it in an Apply to Each. But if it's in the Expression editor don't, just leave me in the editor.

Apply to Each
![dynamic content](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7a2xtz9x9q3ne7p7vsnv.png)

Not Apply to Each
![expression](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zhxmnsitgxa9la83q6m.png)

---

To be fair to the development team they have been pumping out some cool new features (version control, Dataverse run logs), and working on getting the New UI upto speed so I understand why these little niggles are not a priority.