September 1, 2024

"When a record is selected" Dataverse trigger returns to Power Automate

Previously only available in the Dataverse Legacy Connector, the "When a record is selected" trigger is now available for the standard Dataverse connector.

Where is the "When a record is selected" trigger used?

Before the days of being able to build your own Power Fx buttons in model-driven apps, you could call a flow from the main toolbar and run that flow against one or more records. In doing so, one flow run would be generated for every appropriate record. 'Selected' is a little misleading - you have to select the records you want and then call the Flow from the menu - nothing happens just from clicking your records.

However, when the original Dataverse connector (called the Common Data Service connector initially and now referred to as the Dataverse Legacy Connector) was superseded by the current Dataverse Power Automate connector, the "When a record is selected" functionality was nowhere to be seen. You could still build flows using the legacy connector if you wanted to carry on making use of this functionality, but it felt better to move away from it and either build custom buttons or have flows triggering from record changes instead. With the addition of the old trigger to the present connector, it means we can now use this functionality again.

How does the "When a record is selected" trigger work?

Take this sample flow called "Contact: Deactivate Contact(s)":

Flow - Deactivate Contact
(I've left the action names as their defaults so that you can see which Power Automate trigger and actions I'm using - I would normally rename each step to make the names more descriptive)

It consists of three parts:

  1. The When a record is selected trigger, running on the Contacts table:
    Flow Trigger
  2. A Compose step that just grabs the first name of the selected Contact:
    Compose First Name
  3. An Update a Row step that deactivates the Contact:
    Update a Row
    .
    .
    Contact Status Change

Once the flow has been built and saved, when you return to your model-driven app, you will see your flow in the main toolbar:

  1. Browse to the Contacts table
  2. Select one or more records
  3. Click the Flow menu:
    Run Flow from toolbar
  4. Confirm the running of the flow
    Confirm the Flow run
  5. In the example screenshots above, once the Run Flow button is clicked, three flows will start and the selected Contacts will be deactivated.
    Flows started

The reason for including the Compose step is to illustrate an interesting quirk of the trigger. Usually in a Dataverse flow run, when you trigger from a record change, you will get most of the data from that record passed through to the trigger. However, this new trigger is more efficient and only passes through the data required by the flow. This is illustrated by looking at one of the flow runs:

Flow Trigger outputs

As the flow only needs the contactid field in order to deactivate a record and the firstname field for the compose step, that is all that is passed to the flow.

Passing other data to your Flow

Although just running a flow against the selected records might be enough for most scenarios, you might want to capture some further details from the user that are required by your flow. This can be achieved by adding parameters to your flow trigger:

Any parameters added at this point can then be used in your dynamic content picker:

Dynamic Content

And when you next run the flow from the model-driven app, you'll be prompted to enter the required information:

New Flow trigger

Summary

Although I have since moved on to creating this kind of functionality using a Power Fx button (or a Custom Page called from a Power Fx button), it's still nice to have this old functionality back, as it's very easy for those who aren't familiar with Power Fx to be able to add functionality to their model-driven apps without the need for any editing of the app at all.

Freezepop.co.uk

Informational site covering the Microsoft Power Platform, including Power Apps, Power Automate and Power BI.