Microsoft Dynamics 365 Power Automate Flow for the System Admin – Day 2 Blog

Day 2 Post: List Action Records

Now that we have The Setup completed for a Power Automate Flow, it’s time to set up the first flow action. If you haven’t gone through Day 1: The Set up please take a moment to go through that first.

As a reminder, our scenario is to complete the following:

The Scenario

Let’s assume we want to run an advanced find query against a Dynamics 365 custom entity, loop through the result set, and create a task when we find a data anomaly in our system. For example, perhaps contacts can only be linked to Active Accounts, so let’s find all contacts linked to inactive accounts.   We can then create a task for somebody to investigate each Contact linked to an Inactive account.

Your first flow Action: List records

Our scenario is to loop through an advanced find result set.   To do so, we want to select the “List Records” action.

(9) click the New Step button (and prepare to be overwhelmed for a bit)

There are hundreds of connectors and thousands of actions to choose from.  Unfortunately, finding the one you want is NOT intuitive.  You ultimately have to know what you are looking for.  In this case, we want to query a D365 entity.  So, we want to ALWAYS select “Common Data Environment (current environment)” actions

(10) In the search box, type “Common”

As you can see there are a bunch of actions you can do against your CDS (CRM, Dataflex) database.  The one we want is not listed in this view, so

(11) scroll down until you see the “List records” action, and click it to select

Note that the easiest way to find the desired action is to begin typing in the search box.  It automatically and invisibly prepends the wildcard “*” you know well from CRM, so the search Is a “contains” search on whatever phrase you enter.

After selecting the List records action, your Power Automate flow builder page will look like this:

Filling out the List records action

First, select the entity that contains the data we want to work with.   In our example, we want to see any active contacts linked to inactive account, so

(12) select “Contacts” from the Entity name chooser.

As you type the (friendly) entity name into the Entity name box, the entity list will automatically filter to only show the entities that match what you’ve entered

(13) Click the “Show Advanced Options” button.  You can see there are many ways to write a query or filter to restrict the Contact records that the flow will work with.  We’re going to do the easiest and coolest one that will make all CRM System Admins very happy: Fetch XML Query.

Back in CRM: Create an Advanced Find Query

One of the very coolest things about the List Records flow is that you can run any advanced find query against your D365 CRM/CDS/Dataflex database, and process the result set in a loop!

Yes, “workflows” (Power Automate flows) can now LOOP through a result set!

Create an advanced find query that shows the data we are looking for.

(14) Navigate into your D365 Customer Engagement (a/k/a CRM) app.  Navigate to Contacts and click the Advanced Find icon.  Create an advanced find query, in this case, to find all active contacts linked to inactive accounts.  

(15) When you have the query returning the desired result set, click on the “Download Fetch XML” button.

(Note: if you do not have any records returning from this query…. Make up some data so it will.  You want at least 2 rows returning from any query you build.  Any query will do for this example, as long as it returns a couple of rows.)

(16) I prefer to open FetchXML files in Notepad (instead of Visual Studio or other methods), so I always right click on the FetchXML downloaded file, and select “Show in folder”.

The reason why is that Notepad does not add any minus signs (“-“ ) in front of some of the FetchXML that you have to delete before you paste it in – so using Notepad saves you from this step, and makes it so the FetchXML: you download can just be copied and pasted directly into the Power Automate List Records action.  Notepad also loads way faster than Visual Studio.

(17) Then, I can open Explorer and right-click on the file name and open with Notepad.

(18) Copy all lines of the Fetch XML

CTRL/A to select all, CTRL/C to copy.

Back to our flow

Now, open up your Power Automate flow, and expand the advanced options on your List Records action, and

(19) paste in the Fetch XML you just copied into the Fetch XML Query box.  It will look a lot like this (your advanced find columns may differ, depending on the columns you select)



Leave a Reply

Your email address will not be published. Required fields are marked *