cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
CDarch
Regular Visitor

Saving email attachments using AI Model form data for folder name

I have created a flow that extracts information from email attachments using an AI Model, then moves the attachments to a Sharepoint folder using the extracted data as the folder name. The problem is that it only copies one of the two files to the appropriate folder. The other file doesn't have the AI form data, so it doesn't get scanned, but it needs to go into the same folder as the other file. Here's my flow:

2022-01-15 21_31_37-Untitled-1 @ 100% (Layer 2, RGB_8#) _.jpg

 So the folder that gets created is "Submittal Number". FILE1.PDF has the form data that gets exctracted via AI. FILE2.PDF is a companion file, but doesn't contain any of the form data. When I run the flow, here is how the file structure comes out:

/Shared Documents/Administration/Submittals/Submittal Number/FILE1.PDF

/Shared Documents/Administration/Submittals/FILE2.PDF

 

 

Any help would be much appreciated!

 

1 ACCEPTED SOLUTION

Accepted Solutions
PowerAppsWizard
Resolver II
Resolver II

Initialize a variable of type array before the loop. Then use the loop only to make the AI extract and store the result in the array (Append to array action). Outside the loop create a Filter array action with filtering do not equals null. This should return the one number only.

Now create a new loop to go through each attachment and create file action with your storage string and the Filtered array result (you need to use first or integer pointer to ensure it us only one value!) and store the files.

 

That should work.

View solution in original post

7 REPLIES 7
PowerAppsWizard
Resolver II
Resolver II

The issue is that the second pdf does not have the related data extract... and then the path is just as you state in the folder path hard coded without the AI extract.

You could use a create folder action first only on the first AI scannable file and use this path to sore the second doc in.

Then you have to make sure that always the first doc contains the AI scann info. Does the email always attachments always contain the same file naming?

CDarch
Regular Visitor

Thanks. That is one of the first things I tried, but the problem I ran into was once I created the folder I couldn't figure out how to reference the new folder name in a new step without invoking the AI script again. That basically put me back into the same loop.

The filenames are sometimes different, but the form data is always consistent. Sort of like a cover sheet for a letter, but the letter is a separate attachment.

PowerAppsWizard
Resolver II
Resolver II

Initialize a variable of type array before the loop. Then use the loop only to make the AI extract and store the result in the array (Append to array action). Outside the loop create a Filter array action with filtering do not equals null. This should return the one number only.

Now create a new loop to go through each attachment and create file action with your storage string and the Filtered array result (you need to use first or integer pointer to ensure it us only one value!) and store the files.

 

That should work.

I think that's what I was looking for, but it keeps getting stuck on the second file. The first file processes fine, but when it gets to the second one, it throws an error and stops. I'm a bit new to this, so I may be missing something... here is the error for file #2.

2022-01-16 19_37_11-Run History _ Power Automate.jpg

PowerAppsWizard
Resolver II
Resolver II

Add a condition block action before the append to check whether the return value is not equals null. If it is true append the value else do nothing. That should work.

 

CDarch
Regular Visitor

Almost there! Good suggestion on the condition block. I got that working, and the file creation works, but when I call the variable, it returns ["Folder Name"] instead of just Folder Name. How can I get rid of the brackets and quotes? Here's how it looks. The folder should just be called 07 41 13-4.1.

2022-01-17 11_14_45-Run History _ Power Automate.jpg

CDarch
Regular Visitor

@PowerAppsWizard Thanks for all your help. I figured out the last part and everything is working. Just for record purposes, here's what I did: 

After the append, I set an Initialize variable block to switch the Folder Name variable to a string. Then, a Compose block to remove the quotes/brackets which looks like this 

replace(replace(replace(variables('FolderString'),'[',''),'"',''),']','')

Then I ran a Create file, using the Compose output for the new folder name.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Top Kudoed Authors
Users online (2,039)