Article by Jessica Corbett, CRMCS Dynamics 365 Consultant 
PowerApps provides the framework to integrate data seamlessly across different Microsoft apps in real time, rather than having to export and import data, or copy data across manually. One effective application that I worked on was using automated Flow (Power Automate) to integrate Forms with Dynamics.
We have a form where people can submit their contact details if they wish to be kept up to date with our monthly CRMCS Webinars. The aim of this job was to run a flow on the form submission, to check our database for a duplicate contacts, and if one existed then to update that contact, and if none existed then to create a new contact.
In this article I’m going to explain all the flow steps I used to get to this goal!
STEP 1 - Get the details from the form submission
We want to trigger this Flow every time this particular Microsoft Form is submitted. To do this, we’ll be:
- Creating a new flow starting with ‘Automated – from blank’.
- Then name the Flow, and select the first trigger as ‘When a new response is submitted’ in the Microsoft Forms triggers.
- When you’ve selected the form, select the data from the submitted form into your Flow.
- To do this, click add new step, and find ‘Get response details’ in the Microsoft Forms section.
- You can now fill in the ‘Form Id’ with the same form as in the first step, and then find the ‘Response Id’ from the dynamic content window from your first step.
STEP 2 - Initialise the variable
Next we want to ‘Initialise a variable’. This variable will essentially be a placeholder that we can increment as we search the database for duplicates, and will then dictate whether we need to create a new contact or not afterwards.
Find ‘initialise a variable’ under the actions area in the flow step, give the variable a name, and then set this to 0.

STEP 3 - Search the database for duplicate contacts
Now we need to search the database for any duplicate contacts, using the ‘List records’ action under the Common Data Service (current environment)’ actions.
Select the entity, then use the ODATA filter query field to specify what exactly you want to search on. (I only want to search based on the same email address, so I’m going to use the database field name and bring in the dynamic data from the form to make the following query: “emailaddress1 eq ‘[Email Address]’)

STEP 4 - Update any duplicate contacts
We now want to add 1 to our variable for any contact that the search finds, then also update that contact record to update a Boolean field for ‘Webinar updates’ to ‘Yes’.
To do this, we need to:
Use the ‘Apply to each’ step control – this allows us to perform an action for each record the filtered query finds (if it finds any).
Select this step, then find the dynamic content ‘Value’ from your ‘List records’ step, and then define your actions. (I’m going to have two actions, one ‘Increment Variable’ – adds 1 to my pre-defined variable, and another ‘Update a record’ under the Common Data Service (current environment) to update the found contact record).

N.B the important thing to remember when updating a contact record is to set the Item ID to the ‘Current item’ from the ‘Apply to Each’ flow step.
STEP 5 - If no duplicate is found, create a new contact
This flow will now run through the database and update any existing contact.
The last step is where we’ll create a new record, if no duplicate value is found. For this, we can use a condition step, to interrogate the variable.
If the flow has not found any duplicates, then the variable I set should still be equal to 0. Therefore I’m going to set a condition to say if the variable is greater than 0, then nothing should happen, and if it is not, then add a new action step ‘Create a record’ from the Common Data Service (current environment).
From here, I chose ‘Contacts’ as the entity, and then mapped every form field to the relevant field in our contact entity, using the dynamic content panel, and setting any static fields as required.

N.B. If you have a dropdown field in your entity that you want to fill in from the form, you need to ensure that all options from the form match to options in the entity, and you must click ‘Enter Custom Value’ when selecting that field to populate with the dynamic value

We hope you found this technical article useful, visit our Website for more Technical Articles including Microsoft Teams, PowerApps Portals, Dynamics 365 Marketing and more…
CRMCS RELATED ARTICLES : Flow – Getting Stuck in for Dynamics 365 https://www.crmcs.co.uk/content/building-and-testing-a-flow-for-dynamics.aspx