How to use MS FLow and ODATA to filter a document library on file name?

Frequent Contributor

Hi, I'm trying to filter a SharePoint document library using ODATA in the Get Items action in Flow. I can for example use the ODATA expression startswith(Title,'abc') to make it filter on the Title column, but if I do the same with the Name column. i.e. startswith(Name,'abc') stating the Name column doesn't exist.


How come? And is there a way around this?

10 Replies
best response confirmed by Erik Wettergren (Frequent Contributor)

@Erik Wettergren 




Instead of using name as the filter, try FileLeafRef - Annotation 2019-05-01 112943.jpg


I was able to return all files from this library whose names start with the letter H.


Hope this helps.


Terry McCullagh

It certainly helps!

Just out of curiosity - how did you figure this one out? From the SharePoint Search Schema?


Thank you!

By the way, tried to do a similar operation using substringof instead of startswith. Oddly though this didn't work unless I switched places of the FileLeafRef variable and the substring to filter on.



@Erik Wettergren 




I've found the Odata Query Builder from Authur Graus to be extremely helpful in constructing the correct queries.


This article is also helpful:





Hi and thanks again! Great tip about the Query Builder and a useful article.

Erik - Glad to have been of assistance.

@Terry McCullagh 


First of all, *thank you* for this solution, it's great ... and has saved me *hours*.


Secondly, I should say that I haven't come here to doubt anything. However, I noted that this stack notes that FileLeafRef is a bit ... flighty?


Is there a chance that this isn't the most reliable method, and we need to build a little logic scope to filter, as per Alice's ( @v-yuazh-msft ) answer in this question to be totally sure?:





Thank you for reaching out and I'm glad this solution has saved you time. 


I reviewed the posts you referenced and cannot comment on those since I haven't taken the time to try to reproduce any errors that may arise.  


What I can say with certainty is using the solution as accepted by @Erik Wettergren has worked for me in many a SharePoint tenant. 


Perhaps @v-yuazh-msft can elaborate on the benefits of their answer. 





@Terry McCullagh ... Nice one, and thanks for the response, I respect that you didn't have to say anything! :)


I think that the approach that I will take is belt and braces. I'll ensure that I've got a fully annotated (commented) 'Pure Flow Logic' available to the user in what I call 'The Worst Timeline' * so that if it fails, then whomever is managing it can switch to that.


Thanks again, mate! :)



* A community reference used to describe a testing branch that I put in most Flows these days via a condition that's always set to run the main line. It'll contain notes, working (how did we get this JSON sample?), and alternates or future parts of the flow, plus some nonsense. Since it's not exactly the easiest place to organise separate Flows (at least, for free users) this feels like the easiest way to ensure that knowledge is available.

Hello I have a problem with filtering. I used condition attachmentname ends with .pdf but one of three folders still accepts and .png format files. How I can resolve this?