How to identify if a row was created or modified in power automate flow and “Switch” accordingly?

Suppose we’re working with the Accounts table in Power Automate, and we want to handle two different scenarios within a single flow: one when an account record is created, and another when it’s modified. Instead of creating two separate flows, we can use a Switch control to manage both scenarios in one flow.

To do this, we first need to determine whether the trigger event was a creation or a modification of the record.

Let’s explore how to achieve this in the following scenario.

  • Create an automated cloud flow.
    A screenshot of a computer

AI-generated content may be incorrect.
  • Specify the flow name, say “Account – identify Change Type”.
  • Select Microsoft Dataverse trigger “When a row is added, modified or deleted”.
    A screenshot of a computer

AI-generated content may be incorrect.
  • Specify trigger properties, say:
    • Change type – Added or Modified
    • Table Name – Accounts
    • Scope – Organization

A screenshot of a computer

AI-generated content may be incorrect.

  • Add a “Compose” action.
  • In the compose properties, specify the following expression. This used to determine whether a record was just created or has been modified since its creation.
if(equals(triggerOutputs()?[‘body/createdon’], triggerOutputs()?[‘body/modifiedon’]), ‘Created’, ‘Modified’)

What does the expression mean?

  • triggerOutputs()?[‘body/createdon’]: This retrieves the timestamp of when the item (like a record or file) was created.
  • triggerOutputs()?[‘body/modifiedon’]: This retrieves the timestamp of when the item was last modified.
  • equals(…): This function checks if the two timestamps are exactly the same.
  • if(condition, ‘Created’, ‘Modified’): This is a conditional statement:
    • If the condition is true (i.e., the item was not modified after creation), it returns ‘Created’.
    • If the condition is false (i.e., the item was modified after creation), it returns ‘Modified’.

A screenshot of a computer

AI-generated content may be incorrect.

  • Add a “Switch” control.
  • In Switch control parameter specify the output from Compose action.
    Screens screenshot of a computer

AI-generated content may be incorrect.
  • Now add cases with following settings:
    • Case 1 equals ‘Created’
    • Case 2 equals ‘Modified’
  • Rename the Case labels (optional).

A screenshot of a computer

AI-generated content may be incorrect.

There you go, now within each case you can carry out relevant actions! 😊

This entry was posted in D365 Customer Engagement (CRM), D365 Tips & Tricks, Power Automate. Bookmark the permalink.

Leave a Reply

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