Forum Discussion
How to handle single quotes in the filter property with Get Items actions
If you are using the SharePoint Get Items actions and using the Odata Filter Query syntax, then you need to handle single quotes in your filter syntax.
Since a single quote is a special character, you need to use another special character to "escape" it. This lets the system know that the next character should be treated as a regular character rather than what it usually means.
In other languages, the escape character could be a backslash, however in Power Automate, the escape character is a single quote. So, to escape a single quote, you need to type two single quotes. We can use the replace function to perform this opearation
Let's have a look at a standard replace function first:
This will look for any occurrence of 'this' in my Filename variable and replace with 'that'.
Now, here's what it looks like when we want to replace single quotes with two single quotes:
Here is the text version. note that there are no double quotes here, only multiple single quotes:
FileLeafRef eq 'replace(variables('FileName'),'''','''''')'
Here is an explanation of the colour coding:
- Everything between the 'green quotes' is a Power Automate expression, not plain text
- The 'yellow quotes' are normal quotes for wrapping strings, e.g. replace(myVariable,'this', 'that')
- The 'light blue quotes' are there to escape the following character (a single quote)
- The pink quote (') is the character to find
- The two orange quotes (') are the characters to replace the found text with
- VijayBhatCopper ContributorThank you..
- Chivalry_lanboCopper ContributorThank you so much, it helps
- Kevin2000Copper Contributor
IvanWilson So if I want to replace an apostrophe with a single quote would it be???
'FileLeafRef eq 'replace(variables('FileName'),''`','''')'
Kevin2000 You can use this filter:
FileLeafRef eq 'replace(variables('FileName'),'`','''')'
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
ganeshsanap To convert the later part to expression automatically, try:
FileLeafRef eq '@{replace(variables('FileName'),'`','''')}'
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- IronArmCopper ContributorThat works, but you don't always have to do that. For example, with "Get files (properties only)" you're going to loop through the results anyway, so you can just add a condition: filename "is equal to" filename. The quotes are handled for you in this case.