How to handle single quotes in the filter property with Get Items actions

Iron Contributor

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:

2021-08-06_9-08-33.png

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:

2021-08-06_8-59-55.png

 

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:

  1. Everything between the 'green quotes' is a Power Automate expression, not plain text
  2. The 'yellow quotes' are normal quotes for wrapping strings, e.g. replace(myVariable,'this', 'that')
  3. The 'light blue quotes' are there to escape the following character (a single quote)
  4. The pink quote (') is the character to find
  5. The two orange quotes (') are the characters to replace the found text with
7 Replies

@Ivan Wilson 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.

Logged in, looked at ellipsis and all over but do not see any place to mark "Mark as Best Response", but above was the best response and it worked.
That 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.