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

Naming attachments sequentially in Flow

This is my first post to these forums so please forgive any lack of following conventions here.

I have a reasonably sized flow that takes incoming emails sent to a particular address, strips off certain information, and sends that info to planner and sharepoint. The email's content is backed up to SP, as are attachments, and certain variables (job reference numbers, cost codes etc) are saved to a list.

I have a 95% success rate but am falling down on a few key points that connect mostly to the naming of the attachments.

Up to now I have been naming attachments with a variable {SubjectSR} then the name of the attachment, this would produce something like: SR12345678 Ground Floor of Hospital.pdf

But on occasion I'd get an instance where someone names a file something so long that planner won't accept the length of the name... 

SR12345678 Ground Floor of Hospital and my office is the one beside the vending machines if you have got to the carpark pay machine then you have gone too far if you need more directions please call my office number using extension 40424.pdf

Seriously.

What I want to produce is: SR12345678_1.pdf, then the next attachment in that email, SR12345678_2.pdf.

I can get the file extension but I can't get a reliable way to name the files sequentially.

1 ACCEPTED SOLUTION

Accepted Solutions

@manuelstgomes 

I have actually resolved this as of last night.

I was able to rework the order to eliminate the first Apply to Each. When I looked back at my historical documentation (yes I actually screenshot my full flow with the custom expressions in the notes, and then print that off), the first Apply to Each wasn't there. I suspect it added itself at a point and it worked but with the second apply to each and because of the naming process it became malignant.

Unfortunately no easy way to remove a top level Apply to Each, except to reconstruct that part of the flow in a new scope.

Thanks for your help though!!

View solution in original post

9 REPLIES 9
manuelstgomes
Community Champion
Community Champion

Hi @TidalCreative 

 

Wow, that's a long and creative name for a file :).

 

Can I propose using random numbers instead? Then you don't need to keep up of sequences or anything of sorts. Here's a formula that you can use to name the file:

 

concat(rand(10000,999999),'.pdf')

 

As I understand it, the number is not essential, the point is to get a smaller name into SharePoint, so this solution should work fine for you.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

 

Hi @manuelstgomes 

Really appreciate the suggestion and it 1/2 works.

In order to write to planner correctly I have to use scope>condition "equals(body('Get_email')?['HasAttachment'],true)" > if yes > Apply to each > Get Attachment name > Split for extension > Write extension > Write Random file number + Extension > Create SP item

Then I have to use another scope to update planner with a sharing link to the file, previous attempts to do this in one scope failed. However I cannot pull the file name produced in the previous scope, and I can't redo the above steps in the new scope because it will create a new random number. I'm not aware of a way to extract info out of one scope for another.

@manuelstgomes 

Ok I now have it all in one scope and it...kinda works but it's quite broken.

Here's what I have. It gets caught in a loop until I stop it. Produces file names exactly as I need but it just doesn't stop.

Here's a link to a screen shot, it won't let me post the "photo"

 

CWT loop scope 

HI @TidalCreative 

 

All looks good to me, but we'll figure this out.

 

When you run the Flow and it keeps on going, can you stop (press "Cancel") its execution and see what is the step that it's getting stuck?

 

Probably that will give us more information to proceed.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

@manuelstgomes 

Ok so after a fair bit of testing the common issue is that the file naming seems to be caught in a loop and is applying the naming action to each attachment 3+ times, creating multiple copies of the same file, each with a different random number.

Karl

@manuelstgomes 

 

Ah ha! Perhaps this will help.

I have discovered the loop is only happening where an email has more than one attachment. If an email has 3 attachments, it will loop 3 times creating 9 items.

I am thinking this is connected to Apply to Each.

I have a Scope>Apply to Each>Condition>Yes/No>If Yes>Apply to each>Attachment File Name>Split off extension > rewrite the extension with "." > write and combine random number and rewritten extension > create file in SP > get metadata > create sharing link > update task details

 

Karl

Hey @TidalCreative 

 

You're on to something. Indeed that could be the case. 

 

But it's strange why it's running 3 times each... Probably the first "Apply to Each" is running 3 times more than supposed to. 

 

We're almost there. What's the first "Apply to Each" testing for? 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

@manuelstgomes 

I have actually resolved this as of last night.

I was able to rework the order to eliminate the first Apply to Each. When I looked back at my historical documentation (yes I actually screenshot my full flow with the custom expressions in the notes, and then print that off), the first Apply to Each wasn't there. I suspect it added itself at a point and it worked but with the second apply to each and because of the naming process it became malignant.

Unfortunately no easy way to remove a top level Apply to Each, except to reconstruct that part of the flow in a new scope.

Thanks for your help though!!

Hey @TidalCreative 

 

Awesome! Problem solved. Well done! 🙂

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

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 (5,819)