In the previous blog entry, I created a simple Flow to create a CRM Contact from a SharePoint List. In this tutorial, I’ll add a condition to prevent duplicate Contacts based on the email address. This tutorial assumes you have a working Flow between SharePoint online and Dynamics 365 (online).
- Access My Flows and open the Flow between SharePoint online and Dynamics 365 labeled, “When an item is create -> Create a new record”
- Edit the flow and click on the plus sign in between the SharePoint trigger and the Dynamics 365 action. In the menu, click on Add an action.
- Search for Dynamics 365 and select the action, Dynamics 365 – List records
- In the new Action, fill in the Organization Name and select Contacts in the Entity Name field. Click on the Show advanced options link.
- With the advanced options expanded, first enter, emailaddress eq ‘’ (two single quotes) in the Filter Query field.
- Add an expression in between the two single quotes. Click once on the Filter Query field and in the pop-up menu, click on Expression and under the String functions, select the toLower(text) expression.
- Click once in the Expression field within the parenthesis and then click on Dynamic content.
- In the list of Dynamic content, select the Email Address field. The Expression should update the value to read, toLower(triggerBody()?[‘Title’]) Don’t forget to click on the OK button.
- The Filter Query field should look like this and the List records action should return an array of objects where the CRM Contacts Email Address is equal to the Email field in the SharePoint list.
- Click on the plus sign in between the List records and Create a new record actions. In the menu, select Add a condition
- In the new Condition, click on Expression and add the value, empty(body(‘List_records’)?[‘value’]) and click on the OK button.
- In Condition, click on the value field and click on Expression. Add the value, true and click on the OK button.
- The Condition should look like this:
(Basic mode)
(Advanced mode)
- Before adding actions to the Condition result, delete the original Create a new record action.
- Under the Yes result. Click on Add an action button.
- Search for Dynamics 365 and select the Create a new record action.
- Fill in the Dynamics 365 fields. Be sure to choose the SharePoint online field values.
- Now click on the Update flow button at the top of the page.
- Go to the SharePoint list and create new Contact. Try to create a duplicate Contact using the same email address.
- Once saved go back to Flow and open the Flow to see the Run History. Click on the top record.
- In the flow results details, the Condition Expression result should return false