cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JesperTorp
Level: Powered On

Parsing the name of attachments in a mail

So, im building this flow, where i have a mail with several attachments. These attachments needs to be saved in a sharepoint folder structure, based on the attachement's name. The attachment names are the names of our employees. The folder structure is build like this, on the first level we have folders names A,B,C,D.....X. Beneath each of these there are one folder for each employee, where the foldername are the persons full name.

 

So i want the attachment called "John Doe.pdf" to be saved in this subfolder: "/J/John Doe/". The attachment "Sarah John.pdf" to be saved in this subfolder: /S/Sarah John/". All these folders allready exists.

 

To accomplish this, i have tried to parse the filename for each attachment in the mail using the  Substring() expression. This is where it fails, as i cannot get MSFlow to give me the attachment names as a type string i can work with, the "Attachment Name" is an object.

 

As seen here, i want to be able to use RegEx's to be able to tell flow, where to put each file, in the folder path.

 

Anyknow know if this is at all possible ?

 

flow.png

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Parsing the name of attachments in a mail

Hi @JesperTorp,

 

I have made a test on my side and please take a try with the following workaround:

  • Add a "When a new email arrives" trigger, Has Attachment field and Include Attachments field both set to Yes.
  • Add a "Apply to each" action, input parameter set to Attachments dynamic content of the trigger.
  • Within "Apply to each" action, add a "Create file" action, specify Site Address and List Name. Folder Path field set to following formula:
/Reporting/substring(...)​/split(...)

The substring(...) expression within above formula read as below:

substring(split(item()?['Name'],'.')[0],0,1)

The split(...) expression within above formula read as below:

split(item()?['Name'],'.')[0]

The File Name field set to following formula:

concat(triggerBody()?['DateTimeReceived'],'.',split(item()?['Name'],'.')[1])

The File Content field set to Content dynamic content of the trigger.

 

Image reference:18.JPG

The flow works successfully as below:19.JPG

 

20.JPG

 

21.JPG

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 REPLIES 3
Community Support Team
Community Support Team

Re: Parsing the name of attachments in a mail

Hi @JesperTorp,

 

I have made a test on my side and please take a try with the following workaround:

  • Add a "When a new email arrives" trigger, Has Attachment field and Include Attachments field both set to Yes.
  • Add a "Apply to each" action, input parameter set to Attachments dynamic content of the trigger.
  • Within "Apply to each" action, add a "Create file" action, specify Site Address and List Name. Folder Path field set to following formula:
/Reporting/substring(...)​/split(...)

The substring(...) expression within above formula read as below:

substring(split(item()?['Name'],'.')[0],0,1)

The split(...) expression within above formula read as below:

split(item()?['Name'],'.')[0]

The File Name field set to following formula:

concat(triggerBody()?['DateTimeReceived'],'.',split(item()?['Name'],'.')[1])

The File Content field set to Content dynamic content of the trigger.

 

Image reference:18.JPG

The flow works successfully as below:19.JPG

 

20.JPG

 

21.JPG

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
JesperTorp
Level: Powered On

Re: Parsing the name of attachments in a mail

Yes, Yes, YES...that was E X A C T L Y what i needed, and it worked like a charm. Thx Smiley Happy

Highlighted
NishantAgr
Level: Powered On

Re: Parsing the name of attachments in a mail

 

 

@v-xida-msft - Can you please help me out with steps. Please have a look at my scenario:

Suppose file name is IN_2019_02_07_Invoice.pdf

  • Let’s have sample librarie in the SharePoint site – Invoice
  • Once the file is received via the email, let’s move the files into heirarical folders, Invoice->IN->2019->02->07 these folders are based on Country Code/Current Year/Month/Date.. County code (IN, PO, BU, DE...) in File Name.
  • Also, moving files into folders based on year ->  month will be ‘nice to have’ or even date wise within these libraries

 

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 119 members 3,783 guests
Please welcome our newest community members: