SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-504154%22%20slang%3D%22en-US%22%3EHow%20to%20use%20MS%20FLow%20and%20ODATA%20to%20filter%20a%20document%20library%20on%20file%20name%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-504154%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%20I'm%20trying%20to%20filter%20a%20SharePoint%20document%20library%20using%20ODATA%20in%20the%20Get%20Items%20action%20in%20Flow.%20I%20can%20for%20example%20use%20the%20ODATA%20expression%20%3CEM%3Estartswith(Title%2C'abc')%3C%2FEM%3E%20to%20make%20it%20filter%20on%20the%20Title%20column%2C%20but%20if%20I%20do%20the%20same%20with%20the%20Name%20column.%20i.e.%26nbsp%3B%3CEM%3Estartswith(Name%2C'abc')%20%3C%2FEM%3Estating%20the%20Name%20column%20doesn't%20exist.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20come%3F%20And%20is%20there%20a%20way%20around%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-504154%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20Flow%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-508234%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20MS%20FLow%20and%20ODATA%20to%20filter%20a%20document%20library%20on%20file%20name%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-508234%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F116192%22%20target%3D%22_blank%22%3E%40Erik%20Wettergren%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EErik%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EInstead%20of%20using%20name%20as%20the%20filter%2C%20try%20FileLeafRef%20-%20%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111370i15F2387BA5F586B6%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22Annotation%202019-05-01%20112943.jpg%22%20title%3D%22Annotation%202019-05-01%20112943.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20was%20able%20to%20return%20all%20files%20from%20this%20library%20whose%20names%20start%20with%20the%20letter%20H.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20helps.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETerry%20McCullagh%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-510832%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20MS%20FLow%20and%20ODATA%20to%20filter%20a%20document%20library%20on%20file%20name%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-510832%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20certainly%20helps!%3CBR%20%2F%3E%3CBR%20%2F%3EJust%20out%20of%20curiosity%20-%20how%20did%20you%20figure%20this%20one%20out%3F%20From%20the%20SharePoint%20Search%20Schema%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-511239%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20MS%20FLow%20and%20ODATA%20to%20filter%20a%20document%20library%20on%20file%20name%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-511239%22%20slang%3D%22en-US%22%3E%3CP%3EBy%20the%20way%2C%20tried%20to%20do%20a%20similar%20operation%20using%20%3CEM%3Esubstringof%26nbsp%3B%3C%2FEM%3Einstead%20of%20%3CEM%3Estartswith.%20%3C%2FEM%3EOddly%20though%20this%20didn't%20work%20unless%20I%20switched%20places%20of%20the%20FileLeafRef%20variable%20and%20the%20substring%20to%20filter%20on.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-511921%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20MS%20FLow%20and%20ODATA%20to%20filter%20a%20document%20library%20on%20file%20name%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-511921%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F116192%22%20target%3D%22_blank%22%3E%40Erik%20Wettergren%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EErik%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20found%20the%20Odata%20Query%20Builder%20from%20Authur%20Graus%20to%20be%20extremely%20helpful%20in%20constructing%20the%20correct%20queries.%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fappsource.microsoft.com%2Fen-us%2Fproduct%2Foffice%2FWA104051159%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fappsource.microsoft.com%2Fen-us%2Fproduct%2Foffice%2FWA104051159%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20article%20is%20also%20helpful%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fsp-add-ins%2Fuse-odata-query-operations-in-sharepoint-rest-requests%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fsp-add-ins%2Fuse-odata-query-operations-in-sharepoint-rest-requests%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETerry%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-535087%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20MS%20FLow%20and%20ODATA%20to%20filter%20a%20document%20library%20on%20file%20name%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-535087%22%20slang%3D%22en-US%22%3EHi%20and%20thanks%20again!%20Great%20tip%20about%20the%20Query%20Builder%20and%20a%20useful%20article.%3CBR%20%2F%3E%3CBR%20%2F%3E%2FErik%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-548418%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20MS%20FLow%20and%20ODATA%20to%20filter%20a%20document%20library%20on%20file%20name%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-548418%22%20slang%3D%22en-US%22%3EErik%20-%20Glad%20to%20have%20been%20of%20assistance.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-908428%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20MS%20FLow%20and%20ODATA%20to%20filter%20a%20document%20library%20on%20file%20name%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-908428%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5149%22%20target%3D%22_blank%22%3E%40Terry%20McCullagh%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFirst%20of%20all%2C%20*thank%20you*%20for%20this%20solution%2C%20it's%20great%20...%20and%20has%20saved%20me%20*hours*.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESecondly%2C%20I%20should%20say%20that%20I%20haven't%20come%20here%20to%20doubt%20anything.%20However%2C%20I%20noted%20that%20this%20stack%20notes%20that%20FileLeafRef%20is%20a%20bit%20...%20%3CEM%3Eflighty%3C%2FEM%3E%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fsharepoint.stackexchange.com%2Fquestions%2F241067%2Fhow-to-read-the-name-column-in-a-sharepoint-document-library%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsharepoint.stackexchange.com%2Fquestions%2F241067%2Fhow-to-read-the-name-column-in-a-sharepoint-document-library%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20a%20chance%20that%20this%20isn't%20the%20most%20reliable%20method%2C%20and%20we%20need%20to%20build%20a%20little%20logic%20scope%20to%20filter%2C%20as%20per%20Alice's%20(%20%40v-yuazh-msft%20)%20answer%20in%20this%20question%20to%20be%20totally%20sure%3F%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fpowerusers.microsoft.com%2Ft5%2FGeneral-Flow-Discussion%2FGet-File-Properties-from-File-Name%2Ftd-p%2F157860%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fpowerusers.microsoft.com%2Ft5%2FGeneral-Flow-Discussion%2FGet-File-Properties-from-File-Name%2Ftd-p%2F157860%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-913038%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20MS%20FLow%20and%20ODATA%20to%20filter%20a%20document%20library%20on%20file%20name%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-913038%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F376504%22%20target%3D%22_blank%22%3E%40eliotcole-projectfive%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEliot%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20reaching%20out%20and%20I'm%20glad%20this%20solution%20has%20saved%20you%20time.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20reviewed%20the%20posts%20you%20referenced%20and%20cannot%20comment%20on%20those%20since%20I%20haven't%20taken%20the%20time%20to%20try%20to%20reproduce%20any%20errors%20that%20may%20arise.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20I%20can%20say%20with%20certainty%20is%20using%20the%20solution%20as%20accepted%20by%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F116192%22%20target%3D%22_blank%22%3E%40Erik%20Wettergren%3C%2FA%3E%26nbsp%3Bhas%20worked%20for%20me%20in%20many%20a%20SharePoint%20tenant.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPerhaps%20%40v-yuazh-msft%20can%20elaborate%20on%20the%20benefits%20of%20their%20answer.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETerry%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-915019%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20use%20MS%20FLow%20and%20ODATA%20to%20filter%20a%20document%20library%20on%20file%20name%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-915019%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5149%22%20target%3D%22_blank%22%3E%40Terry%20McCullagh%3C%2FA%3E%26nbsp%3B...%20Nice%20one%2C%20and%20thanks%20for%20the%20response%2C%20I%20respect%20that%20you%20didn't%20have%20to%20say%20anything!%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20think%20that%20the%20approach%20that%20I%20will%20take%20is%20belt%20and%20braces.%20I'll%20ensure%20that%20I've%20got%20a%20fully%20annotated%20(commented)%20'Pure%20Flow%20Logic'%20available%20to%20the%20user%20in%20what%20I%20call%20'The%20Worst%20Timeline'%20*%20so%20that%20if%20it%20fails%2C%20then%20whomever%20is%20managing%20it%20can%20switch%20to%20that.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20again%2C%20mate!%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E*%20A%20community%20reference%20used%20to%20describe%20a%20testing%20branch%20that%20I%20put%20in%20most%20Flows%20these%20days%20via%20a%20condition%20that's%20always%20set%20to%20run%20the%20main%20line.%20It'll%20contain%20notes%2C%20working%20(how%20did%20we%20get%20this%20JSON%20sample%3F)%2C%20and%20alternates%20or%20future%20parts%20of%20the%20flow%2C%20plus%20some%20nonsense.%20Since%20it's%20not%20exactly%20the%20easiest%20place%20to%20organise%20separate%20Flows%20(at%20least%2C%20for%20free%20users)%20this%20feels%20like%20the%20easiest%20way%20to%20ensure%20that%20knowledge%20is%20available.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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?

9 Replies
Highlighted
Solution

@Erik Wettergren 

 

Erik,

 

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

Highlighted

It certainly helps!

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

 

Thank you!

Highlighted

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.

 

 

Highlighted

@Erik Wettergren 

 

Erik,

 

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

https://appsource.microsoft.com/en-us/product/office/WA104051159

 

This article is also helpful:

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/use-odata-query-operations-in-sharepoint-...

 

Regards,

 

Terry

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

/Erik
Highlighted
Erik - Glad to have been of assistance.
Highlighted

@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?

 

https://sharepoint.stackexchange.com/questions/241067/how-to-read-the-name-column-in-a-sharepoint-do...

 

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?:

https://powerusers.microsoft.com/t5/General-Flow-Discussion/Get-File-Properties-from-File-Name/td-p/...

Highlighted

@eliotcole-projectfive 

 

Eliot,

 

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. 

 

Regards,

 

Terry

Highlighted

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