Flow to Replace Special Characters from any text Field in Dynamics 365
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.
- Replace the Special Character Using Variable in the flow itself.
- Replace the Special Character in the Record.
- 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: –
- The Flow will run the flow when an Opportunity is Created.
- The Flow will get the Topic of the Opportunity.
- The Flow will Check if the Topic Name Has Any Special Characters
- If YES
- The Flow Will check which Special character it is and replace the Topic name Accordingly.
- After the name is being updated the flow will Update the Opportunity Record.
- If NO
- The flow will terminate successfully.
- If YES
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 – 5 “createArray(‘.’,’@’,’ß’,’²’,’³’,’µ’,’`’,’´’,’°’,’^’,’=’,'(‘,’)’,’&’,’$’,’§’, ‘~’,’#’,’%’,’*’,’:’,'<‘,’>’,’?’,’/’,’|’,’ ‘) “
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 !.