In one of our blogs we have seen how to update existing records in CDS (Common Data Service) using Microsoft flow in Dynamics 365 CRM.
But recently we came across a scenario where we wanted to update a Contact record based on First name, Last name & EmailAddress using Microsoft Flow.
However, while retrieving the list of Lead records we faced an error 400. This error was caused because there was special character like Single Quote (’) in the Last name.
So to overcome this issue we replaced the single quote while retrieving the contact records. In order to achieve this, we have to write a query to replace a single quote from the attribute. We will store this query in the variable and use the variable to retrieve entity records.
Please follow the below steps to add a variable:
1. Before retrieving the lead record we have to add a step to initialize variable. For that add an Action and in the action search for Variables as shown in the given image.
2. After selecting Initialize variable in the name attribute you can give a name to your variable and in String type select type as a ‘String’.
3. In the value we have to write our expression to replace the Single quote from the received attribute in the body. Next, we will store the value in this created String variable. In our scenario we are removing single Quote from LastName attribute. You can find the below query to replace the single Quote from the attribute.
Query = replace(triggerBody()?[‘text_1’],””,”””)
4. Finally, we can use this variable in our retrieve Filter Query as shown below.
5. As shown in below image you can see the successful run history record to retrieve the contact record.
Thus by using this approach we can successfully retrieve the record from Dynamics CRM and perform the operation on records.