cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JustWorking
Frequent Visitor

Get Files properties only in an Apply to Each loop

I am grabbing a list of libraries and using that list as input for an "apply to each" loop that uses "get files (Properties Only)" , and filtering for old modified dates,  I want to email the associates who last modified the file to update the file.

But it seems like I lose all the metadata and properties as dynamic content when my "get files (Properties Only)" is in a loop.

 If someone could help me pull out data using expressions or tell me a better way to iterate through multiple files in multiple libraries it would be appreciated.

 

Apply2Each.png

1 ACCEPTED SOLUTION

Accepted Solutions

No problems, @Caspar_Rubin !

 

If you think about this slightly differently, @JustWorking, you could take the thought process that there's very likely going to be less users involved in modifying more documents than there are going to be as many users as there are documents.

 

So it stands to reason you'd actually economise here if you only sent a single email to each user.

 

So, alongside the Select that I intimated previously, you could have a parralel Select task that makes a list  of purely users' emails. Then run your Apply to each loop on that (you just union the parallel Select) which then sends an email to each user that has modified many files in many locations.

 

This way, each user would only get one email or Teams message which means less harrasment on their end. Plus, in later versions of this flow, you could even have it ask them if a particular file can just be deleted or archived. This would then handle that for you, too. 👍

 

Anyway, I'll try to draw up a rough idea of how that would look for you, but ... yeah ... I think the more that you play with it, the more you'll figure out is possible here.

 

EDIT

 

Here's a look at something that I cobbled together on this, folks (to make the 'Map' field one box, tap the little 'T' icon to its right )

00 - Full Flow.jpg

That union() in the 'Select an output from previous steps' field is:

union(
	body('Select_emails'), 
	body('Select_emails')
)

View solution in original post

10 REPLIES 10
Caspar_Rubin
Solution Supplier
Solution Supplier

Hey, 

 

not sure if I understand correctly but what if you try to use a string or array variable.

 

A variable is basically a container to store data in during loops so you don't lose it. You can then access all that gathered data after the loop is finished to, for example, send out and e-mail.

 

Basically you create a new variable (initialize variable action) at the top level. It's empty at the start but every loop it does inside the "apply to each" action, you add dynamic values to it (append to string (or array) variable action.

 

This is an example flow. I get all the titles from all the files in a library into a single string, separated by comma:

 

Caspar_Rubin_0-1659470276300.png

 

Above flow outputs this in the compose: All titles separated by commas.

 

Caspar_Rubin_1-1659470292997.png

 

does this help?

 

cheers

 

Somewhat,  I have say 20 SharePoint document libraries with hundreds of documents each.   I want to in one flow to search all the libraries, for all files that haven't been modified in xx days, email the address associated with the file.   But if I  use an  "apply to each" loop to iterate through the records for the "get files (properties only)" step.  I can't use dynamic content to pull out the file's information I need.   So I am getting output with all the file information.  But can't access it.   I need dynamic content like below.   If I am to email each associate that their file needs updating, I need access to file name, modified, modified by, email address..   In other words I have the needed information but I can't utilize it for the next step.

 

 

This is just pulled from a test flow, to generate these screenshots.   There is normally a ton of information you can pull using "get files (Properties only)",  but not if it is embedded in a 'apply to each loop"

 

GetfileOpt.png

 

 

 

 

Caspar_Rubin
Solution Supplier
Solution Supplier

I understand. For that, you'd have to manually get that information using expressions.

 

So instead of using dynamic content, you need to use expressions like this:

 

outputs('Get_files_(properties_only)')?['body/value'][0]['Modified']
 
So for example, I use the first compose to output me the dynamic value body. (This step is just to get the right values for building the expressions, you don't need it in the actual flow)
 
this:
Caspar_Rubin_3-1659474354705.png

 

results in:

 
Caspar_Rubin_2-1659474191226.png

 

Note, some loops will fail, that's fine. You can either ignore that or implement a condition to skip empty files, libraries and stuff like that.

 

Once the flow ran, I can then check the values in body by pressing on the "Show raw outputs" link. It opens a window to the right with all the data you can get. I then search for (for example) "Modified" and build my expression, depending on where the value is.
 
In this case: outputs('Get_files_(properties_only)')?['body/value'][0]['Modified'] gives me the Modified date of the looped file.

Caspar_Rubin_1-1659474082386.png

 

 

cheers

 

edit: added a screenshot

First, let me say thanks.  For you to take the time to send all that information, it is appreciated.   I will do some testing today.

eliotcole
Super User
Super User

Hi, @JustWorking, if you place a select item directly after that Get files you can create a more accessible array of data.

 

See this example below, you can see that I've made my own fields, and selected what is important to me:

deletable8.jpg

To get the email address of a user you want to call the Editor/Email key and that will give that information.

 

Then you can filter accordingly.

 

Also give some thought to filtering your 'Get files...' request. 👍

Caspar_Rubin
Solution Supplier
Solution Supplier

I didn't know this @eliotcole , thank you so much!

No problems, @Caspar_Rubin !

 

If you think about this slightly differently, @JustWorking, you could take the thought process that there's very likely going to be less users involved in modifying more documents than there are going to be as many users as there are documents.

 

So it stands to reason you'd actually economise here if you only sent a single email to each user.

 

So, alongside the Select that I intimated previously, you could have a parralel Select task that makes a list  of purely users' emails. Then run your Apply to each loop on that (you just union the parallel Select) which then sends an email to each user that has modified many files in many locations.

 

This way, each user would only get one email or Teams message which means less harrasment on their end. Plus, in later versions of this flow, you could even have it ask them if a particular file can just be deleted or archived. This would then handle that for you, too. 👍

 

Anyway, I'll try to draw up a rough idea of how that would look for you, but ... yeah ... I think the more that you play with it, the more you'll figure out is possible here.

 

EDIT

 

Here's a look at something that I cobbled together on this, folks (to make the 'Map' field one box, tap the little 'T' icon to its right )

00 - Full Flow.jpg

That union() in the 'Select an output from previous steps' field is:

union(
	body('Select_emails'), 
	body('Select_emails')
)

I like the idea of building variables.  But the only options I have when I use the "select" is "output".    Remember the "get files (properties only)"  is embedded in a "apply to each" loop.   This is a nested loop  because I have multiple libraries and that seems to impact the output coming from the "select" as well as the "get file (properties only)".

 

variableoutput.png

This all looks OK, @JustWorking ... I'm not seeing the problem here, sorry ...

I'm struggling with the filter array.    It doesn't seem to want let me select a dynamic content from the "Select Data" step.     It also wants to put it in a apply to each loop automatically when I try and filter the array because it sees it as an array.   Possibly I'm missing something.  I know it's been a while but any help would be apprciated.

 

 

JustWorking_0-1664301004600.png

 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Users online (3,246)