Creating a Flow which triggers where regarding field = lead

I was writing a flow my SMS entity, like the email entity the regarding can be any type. I wanted my Flow to only trigger if the Flow was of type lead.

There is a useful looking Dynamics content

Regarding (Type)

Regarding (Value)

Behind the hood, it’s looking up the logical name (I think)

The values in the output body of my Flow

“_regardingobjectid_value”: “e565622a-6e47-ea11-a812–000d3a4ab4c2”,

“_regardingobjectid_type”: “accounts”,

I only wanted to run the Flow if the regarding type was lead, so I created a condition

I couldn’t get this condition to work and I couldn’t find out what the value because you only see the results

this was my condition

I tried lead, leads and every combination with single and double quotes, true, false, 1, 0. Nothing worked

Looking for help

Finding help is difficult for Flows. I used to put Flow, Dynamics 365, Power Automate in front of the search but the results didn’t bring back anything useful.

SharePoint blogs kept popping up because they embraced Flow a year earlier than Dynamics 365 and Microsoft didn’t allow Flows to be added to solutions. Make sure you use the CDS connector in your Flow and create a Flow service account. The connector will connect to the current environment, which means you don’t have to put in your credentials everytime you deploy to a different environment.

You need the Flow service account because when a user is deleted, all the Flows are deleted, so you don’t want a developer leaving the project and finding all his Flow’s go with him (well deleted).


After trying the brute force approach and failing, I needed a different approach. Looking in Flow for some options I found there were variables. I had seen variables earlier and couldn’t think of any use cases for them because most of the time I wanted to use fields directly in queries.

What if I created a variable and assigned the Regarding Type?

I did that

I quickly learnt you have to initialise a variable first, I made sure to initialise it to be blank ‘’

Run my Flow, lets find out what’s going on

null, the out of the box variable had been null, no wonder my condition wasn’t working. Maybe I’m not using this correctly (I can’t find any documentation for it) but it wasn’t working.

So like Edison making his lightbulb and finding 10000 ways not to make a lightbulb, I had found one way not to create a Flow which only runs when the regarding lookup is a lead.

so how do I get that value in the triggerOutput?

I did some couple of useful blogs on this

I used an expression to get the TriggerOutputs @{triggerOutputs()[‘body/_regardingobjectid_type’]}

I ran it and finally I get the entity type in the regarding box

I put this into my condition and boom it worked.


The Flow I was creating was simple but whilst doing it I think I made every mistake possible.

I used the wrong Common Data Service for selecting and updating records, Microsoft hiding the correct one, meaning you have to search for it is annoying

Using Lead ID rather than Lead

Using Apply to each and thinking current item would give me the guid, it didn’t. I have to select the lead item which was leadid of the correct query.

Creating this Flow taught me a lot, often the way to understand how to do something is by doing it wrong, learning why it doesn’t work and working out the right way.

Mistakes are an effective teacher, it highlights that theoretical knowledge is not as valuable as practical knowledge.