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.
- Specify the flow name, say “Account – identify Change Type”.
- Select Microsoft Dataverse trigger “When a row is added, modified or deleted”.
- Specify trigger properties, say:
- Change type – Added or Modified
- Table Name – Accounts
- Scope – Organization
- 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’.
- Add a “Switch” control.
- In Switch control parameter specify the output from Compose action.
- Now add cases with following settings:
- Case 1 equals ‘Created’
- Case 2 equals ‘Modified’
- Rename the Case labels (optional).
There you go, now within each case you can carry out relevant actions! 😊