Flow to Replace Special Characters from any text Field in Dynamics 365

Posted On January 26, 2021 by Vidit Gholam Posted in  Tagged in

Consider a case where users create a record say an opportunity.

The name of the opportunity may contain special characters such as ampersand “&” and many more.

This might not look like an issue, but these special characters are not accepted if you are trying to fetch a record using query expressions, that may be Fetch XML or any other.

What to do in such case.

There are certain ways in which this issue can be resolved.

  1. Replace the Special Character Using Variable in the flow itself.
  2. Replace the Special Character in the Record.
  3. Or Skip the Special Character.

Let’s have a look on how to Replace the Special Character in the Record.
Consider an Opportunity Record with name as Given Below.

  • As we see that there is an “&” in the name – “COCS – Planning & Discovery“.
  • This can be a cause for a Bad Request error while fetching this record using query expressions.

Solution: –

  1. The Flow will run the flow when an Opportunity is Created.
  2. The Flow will get the Topic of the Opportunity.
  3. The Flow will Check if the Topic Name Has Any Special Characters
    1. If YES
      1. The Flow Will check which Special character it is and replace the Topic name Accordingly.
      2. After the name is being updated the flow will Update the Opportunity Record.
    2. If NO
      1. The flow will terminate successfully.

Let’s Begin with the Flow Implementation.

Process Flow: –

Step – 1 The Flow will trigger when an Opportunity is being created.

Step – 2 The Flow will get the Created Opportunity Record.

Step – 3 Also we need to initialize an array of Special Characters as given below

Step – 4 I have used a Special Character Array “createArray(‘&’,’|’,’/’)” according to my requirement for all special characters you can go with the below expression.

Step – 5createArray(‘.’,’@’,’ß’,’²’,’³’,’µ’,’`’,’´’,’°’,’^’,’=’,'(‘,’)’,’&’,’$’,’§’, ‘~’,’#’,’%’,’*’,’:’,'<‘,’>’,’?’,’/’,’|’,’ ‘)

Step – 6 The Flow will check if the Topic has any special characters.

Step – 7 If Yes, it will replace & with “And” using the Filter query “replace(variables(‘Topic’), item( ),’ and ‘)”

Step – 8 Lastly the flow will update the Topic of the Opportunity.

  • Results

Hope This Helps !.


Share Story :