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

Store attachment, Create folder and check if it already exists.

Hi there, 

for our Night Shelter in South Africa we register about 3000 clients per year. Per client we also create notes and such. What we would like to do is to automate saving attachments into sharepoint. We do have a Flow to store files in a folder, however, it would be great to store files in folders per client. I don't know what to do to make a logical flow and could use some help. 
When an email comes in from our system it has a subject and attachment.

 

Note;{SHELTER:value};{FIRSTN:value}-{SURN:value};{ClientID:value}

The values can change (that will be real names) and only Note will change depending from the input: if it is an admission, or just a note. So as some examples:

1. Note;Kraaifontein;Piet-Jantjies;5x343L
2. Note;Napier Street;Alex-Jansen;4893KK
3. Admission;Paarl;Hope-Xlopa;TDE5XE

 

What I need is the following:
1. The Flow must check in the subject (or the attachment) to what folder the attachment must be stored. The folder path is dynamic, based on the SHELTER. This folder list already exists.  
2. Then a folder must be created within that SHELTER. The folder name must be the Client ID which is based on the subject as well. If the CLIENT folder already exists we don't need another folder but the attachment must be stored.    

Hope my explanation is clear enough. 
Kind regards,
Art
The Haven Night Shelter South Africa

1 ACCEPTED SOLUTION

Accepted Solutions
ArtHavenShelter
Frequent Visitor

Thanks to KvB1 we came to a very nice solution (for us). 
We standardized the subject of the Email. 'file' in the subject line  can be anything. A note, admission, etc..) i.e. 
FILE;{SHELTER:value};{FIRSTN:value}-{SURN:value};{ClientID:value}

In short, when the trigger 'when a new mail arrives' (Shared inbox in this case) gets activated, the subject line is split into multiple variables, split by ';'.
After that there is a check if the 'Shelter' name and the client folder already exists. If not, it will be created. If yes, then the new file will be added to the already existing client folder. 

  1. Start with the Trigger: When a new email arrives (V3)
  2. split(triggerOutputs()?['body/subject'],';')ArtHavenShelter_0-1629827204017.png
  3. ArtHavenShelter_1-1629827309919.png
    variables('SplitSubject')[0]
  4.  ArtHavenShelter_2-1629827432037.png

     

  5. ArtHavenShelter_3-1629827463807.png

     

  6. ArtHavenShelter_4-1629827485630.png

     

  7. ArtHavenShelter_6-1629827769876.png

     


     

  8. ArtHavenShelter_5-1629827604874.png
  9. ArtHavenShelter_7-1629827944338.png

     

  10. ArtHavenShelter_8-1629828051626.png

     

 

View solution in original post

7 REPLIES 7
KvB1
Solution Specialist
Solution Specialist

If I were you I would start off trying to get all the relevant information from the subject line of the mail and store them into variables (shelter, client name, client id). If you are confident that the subject line will be 100% consistent, you could split the line by " ", and then assign the Nth place of the split line to its appropriate variable. If you are not sure the subject line will be 100% consistent, it would be better to include "shelter" etc in the subject line, so you can split on that.

 

I would then use a list folder action, using the shelter variable and client id variable to create folder path. This action will fail if the folder doesnt exist yet, so you can branch 2 actions of the list folder action, configure one to run after the previous action has failed and one to run after the previous action has succeeded. 

 

If it succeeded (folder exists), you can simply create a file using the folderpath stored in your variables. 
It it failed (folder doesnt exist), you can do the same, but you have to create the folder first using the client ID variable as a name.

Hi KvB1,

thanks for your explanation. It sounds very logical. So I think I understand the process. The subject is 100% consistent. Only thing which can change is the first part of a subject. So for example. New Client or Note. The rest will be shelter, client first name, client sur name, client ID. 
Although I follow what you see, I really don't know what to do. If you can be of help I would be very happy. Specially with the splitting of the subject and allocating that to a folder action is hard. 
thanks again!
Gart

KvB1
Solution Specialist
Solution Specialist

Okay, to get a good overview of the information you want to grab and store in a variable, you initialise a array variable and split the subject by ' ' (a space). This becomes tricky when, for example a name contains more or less words than the 2 in your example. Same goes for the shelter. See: 

KvB1_0-1629295670084.png

Then grab the 3rd string from this array by initialising a variable called Shelter with: 

variables('SplitSubject')[2]

KvB1_1-1629295694032.png

 

You can see the problem here, if your shelter contains two words, it will only store the first one since the second word will be a different string in the same array. Similarly, the other strings will have moved a positition relative to your example.

 

If you expect this to be a problem, the only real way to fix this is to have a different character in the subject line to split on, for example: New admission; Kraaifontein; George Philips; Client ID 38dj43

 

KvB1
Solution Specialist
Solution Specialist

(by the way, excuse the dutch, let me know if i should translate it, but maybe its understandable for you ^^)
The allocating folder action would look like this: 

 

KvB1_3-1629296224352.png

You use a list folder action, using the structure of your sharepoint directory, where a library has folder names based on the shelter, which contain folder names on client ID. If you have those sorted from the previous post, create a branch after the action. 

 

One branch will be executed if the list folder action succeeded (folder exists), the other branch will be executed if the list folder action failed (it failed because it can't find the folder, so it doesn't exist yet).

 

You get there by clicking on the marked yellow:

KvB1_4-1629296395535.png

 

Thanks for the extra information. The Dutch I don't mind :-). We do have spaces in names and such, so as you suggested, I changed the standard subject line to:

Note;{SHELTER:value};{FIRSTN:value}-{SURN:value};{ClientID:value}

The values can change (that will be real names) and only Note will change depending from the input: if it is an admission, or just a note. So as some examples:

1. Note;Kraaifontein;Piet-Jantjies;5x343L
2. Note;Napier Street;Alex-Jansen;4893KK
3. Admission;Paarl;Hope-Xlopa;TDE5XE

ArtHavenShelter
Frequent Visitor

Thanks to KvB1 we came to a very nice solution (for us). 
We standardized the subject of the Email. 'file' in the subject line  can be anything. A note, admission, etc..) i.e. 
FILE;{SHELTER:value};{FIRSTN:value}-{SURN:value};{ClientID:value}

In short, when the trigger 'when a new mail arrives' (Shared inbox in this case) gets activated, the subject line is split into multiple variables, split by ';'.
After that there is a check if the 'Shelter' name and the client folder already exists. If not, it will be created. If yes, then the new file will be added to the already existing client folder. 

  1. Start with the Trigger: When a new email arrives (V3)
  2. split(triggerOutputs()?['body/subject'],';')ArtHavenShelter_0-1629827204017.png
  3. ArtHavenShelter_1-1629827309919.png
    variables('SplitSubject')[0]
  4.  ArtHavenShelter_2-1629827432037.png

     

  5. ArtHavenShelter_3-1629827463807.png

     

  6. ArtHavenShelter_4-1629827485630.png

     

  7. ArtHavenShelter_6-1629827769876.png

     


     

  8. ArtHavenShelter_5-1629827604874.png
  9. ArtHavenShelter_7-1629827944338.png

     

  10. ArtHavenShelter_8-1629828051626.png

     

 

View solution in original post

ArtHavenShelter
Frequent Visitor

Extra note: There were some Failed notifications due to an error in List Folder. See my topic: 
encodeUriComponent for List Folder 

I got a message:  The response is not in a JSON format. The issue with this message is that you don't know precisely what to do but I found out it has something to do with the URL that can't be read. There are some topics about encodeUriComponent and that's how I came to the solution: encode it yourself 🙂

 

%2FShared%20Documents%2FsSHELTER%2CLIENTNAME_CLIENTID

 

Apparently the issue was more for the Shared Documents part. It's not a beautiful solution but it works very well. So I manually Encoded the URL. 

 

%20 for Space

%2F for /

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Users online (2,449)