Hello -
I receive auto-generated email reports with the only difference between them is the attachment size. Each email has one of three different attachment sizes. My goal is to have Power Automate look at the size of the attachment and move it to a specific OneDrive folder based on that. Each email has either a 12kb, 25kb or 40kb attachment. The example below is what I tried for an email with a 40kb attachment.
It manages to save a file in the correct folder on OneDrive, however the attachment is corrupt and unable to be opened. The file size is also smaller than what's in the original attachment. Any help will be appreciated. Thanks!
Solved! Go to Solution.
@Mike_S So in this case you don't need the Switch + Variable. You can use an expression in that case. You can delete these actions.
I would recommend temporarily removing the Create File action in your flow. Click on the three dot and select Copy to my clipboard and then delete it. This way you can test the flow to ensure the output of the expression above is correct before you even bother creating the file.
First, we'll need to convert the attachment size from bytes to kb. We'll need to divide the attachment size by 1024 to return the kb value.
Unfortunately, Power Automate turns the expression labels into non-editable labels. Not sure why this is (this wasn't the case before they implemented the new designer).
However, you can access the expression with this trick. Click on the three dots of the Compose action and select Peek Code.
Select the expression which is the text after the @ symbol and before the closing double quote marks. Copy it to your clipboard.
Remove the dynamic content label and click on the expression tab and paste your expression in.
Wrap the expression in a div() function. Place your cursor at the start of your expression by pressing the up arrow key and insert div and an opening bracket.
Go to the end of the expression by pressing the down arrow key and insert a comma and the number 1024 and a closing bracket.
This expression will take the attachment size and convert it to kb. Run a test. Review the outputs.
Add Compose actions to your flow to hold the names of each of the folders you'd like to direct your attachments to based on their size. Using Compose actions for the folder names is optional—however, I recommend this in your case to make it easy to adjust the folder name (should you need to in the future) rather than having to edit the expression.
I've put my actions into a Scope action to make it easy to collapse. This is optional (not required for the flow itself).
Since the Switch action requires an exact match—for this particular scenario I think it would be better to use an expression to set the folder name. We'll be composing an expression with the if() + lessOrEquals() function.
The if() function takes 3 parameters:
The lessOrEquals() function takes two parameters. The value your are checking and
We'll be nesting 3 if() functions + lessOrEquals() function within each other to create the expression. The logic for the expression is as follows:
Tip: Each function needs an opening and closing bracket. Go slow an ensure you are always entering a closing bracket to ensure you aren't missing anything. If you ever have issues and get an alert saying your expression is invalid—throw it into ChatGPT! Sometimes I find it easier to build expressions from the inside out (so I don't forget a bracket). Do whatever works for you.
Additionally to quickly get to the start of the expression: Press the UP arrow key. To get to the end of the expression: Press the DOWN arrow key. Pay attention to the tooltip as it'll bold the text of which parameter of the function you are setting.
Add a Compose action. Click on the Expression tab and insert this expression:
if(lessOrEquals(outputs('Compose_-_Attachment_Size'), 12), outputs('Compose_-_12kb'),
if(lessOrEquals(outputs('Compose_-_Attachment_Size'), 25), outputs('Compose_-_25kb'),
if(lessOrEquals(outputs('Compose_-_Attachment_Size'), 40), outputs('Compose_-_40kb'),
outputs('Compose_-_Default'))))
Depending on how you've named your Compose actions in your flow, you may need to replace the dynamic content references in my expression with the appropriate dynamic content references in yours.
Once the text is highlighted, in the Dynamic content tab and select the appropriate Compose action output.
Run a test. Review the outputs. You can see in my screenshots below the first loop of the Apply to Each action has an attachment that is 8kb, so the output of the folder name is 12kb Folder. The second loop has an attachment that is 15kb and the output of the folder name is 25kb.
Add the Create File action back to your flow. Click on Add an action then click on My clipboard. Select the Create file action.
Replace the variable reference with the output of the compose action above.
Run a test!
Now if you choose to rename your folders, you can edit the Compose actions instead of having to edit the expression.
Hope this helps!
If I helped you solve your problem—please mark my post as a solution ✅. Consider giving me a 👍 if you liked my response! |
@Mike_S I have a different approach to your scenario. To follow along you'll need to switch to the Classic Designer.
Tip: Rename your actions to keep your flow organized!
Click on Show advanced options. Ensure that you've selected Yes for Include attachments and Only with attachments. This way, your flow will continue to run only if the email has attachments.
If you'd like to speed up your flow building process—I'd recommend replacing the automated trigger with a manual trigger. You can watch this section of a YT tutorial to guide you on how to do this. This way you don't need to send yourself an email each time while you build the flow, rather you can manually trigger the flow on an email already in your inbox.
First, you'll need to use a Filter Array action to filter out any attachments under 40kb. Since your requirement is to save attachments that are 12kb, 25kb or 40kb — you should filter out the any attachments over 40kb first.
To learn more about how to use the Filter Array action, please refer to this recent YT Tutorial I uploaded.
Add a Filter Array action after your flow trigger. In the From field, insert the Attachments dynamic content from the flow trigger. Note: I'm using a Get email (V2) action in my flow for demo purposes.
In the first value field, insert the Attachment Size dynamic content. Change the operator to is less than or equal to. In the second value field you can insert the number of bytes you'd like the attachment to be less than or equal to. Attachment sizes are returned in bytes so you will need to convert 40kb in to bytes.
I'm going to use an expression to calculate this. Enter the mul() function into the expression field.
The mul() function takes two numbers and multiplies them. Enter two numbers separated by a comma. In this case 40, 1024.
Add a Compose action to return the count of filtered attachments. In the expressions tab, insert an expression and use the length() function.
Click on the dynamic content tab and insert the body dynamic content from the Filter Array action above.
Run a test. Verify the number of attachments that have been filtered.
Add an Initialize Variable action to your flow. give it a name and select String as the type. A variable is like a container and for your scenario—it'll hold the folder name. We'll set the name of the folder based on your conditions (file size).
Add a Condition action to your flow.
In the first value field, insert the output from the compose action above (the one that has the number of items returned from the Filter Array action).
Change the operator to is not equal to and in the second value field insert a zero.
This condition action will check to see whether or not any attachments are equal to or under 40kb. If so, the flow will continue on. All your remaining actions can go into the YES branch. If you want any actions to take place if there are attachments but none of them are 40kb or under in size—you can add those actions to the NO branch.
Add an Apply to Each action to your flow and insert the body dynamic content from the Filter Array action.
Add a Compose action. I like to use Compose actions to return the dynamic content from a Filter Array action. This can help with troubleshooting. You'll need to get the key for the dynamic content you wan to return.
Refer to this section of a YT Tutorial I uploaded on how to get dynamic content from a Filter Array action.
You can get the dynamic content key from the Filter Array action outputs. The key is the red text between the double quote marks. In this case, you want to return the size of the attachment. The key is 'size'
Insert an expression below.
item()?['']
Between the single quotes, you'll need to insert a key. In this case, it's 'size'
item()?['size']
Add another Compose action to store the Name and Content Byes. Follow the steps above. Important: The keys are case sensitive.
Run a test. Confirm the Compose actions are returning all the dynamic content.
Add a Switch action to your flow.
A Switch action is a control that allows you to add branching paths based the value entered in the switch. Each branching path you add is referred to as a case. The value entered in a case must match the value in the switch.
In the On field, insert the dynamic content from the Compose action above.
You'll need to create a case for each file size you are looking to match. Remember to rename your cases to keep things organized. You'll need to multiply your kb values by 1024 to get the total bytes.
Add a Set Variable action. Set the variable with the appropriate folder name. In my case I'm calling it 12kb.
Add a new case by clicking the + button. Create a case for each of your requirements. Set the variable in each case.
If there is no match to your cases, you will need to set the variable in the default case. This way your attachments will go somewhere (to another folder if they don't match.
In the Folder Path, select a folder (if applicable) and add a forward slash right before you insert your variable. Remember that the variable (aka folder name) will be set in the switch action based on the file size of the attachment.
In the File Name field, insert the outputs from the Compose action that has the attachment name.
12kb, 25kb and 40kb are very specific file sizes. My file sizes do not match those requirements which is why my files will be saved in the Temp folder (which is what the variable was set to in the default case).
The Temp folder didn't exist in my OneDrive (which is why it was automatically created).
All my attachments ended up there.
Hope this helps!
If I helped you solve your problem—please mark my post as a solution ✅. Consider giving me a 👍 if you liked my response! |
Thank you so much for the detailed response. I'm close, but not quite there. I got all the way to the end and realized that each of the attachments that appeared to be the same size are actually bytes different. So even though it says the size is 25KB on an email, the actual byte size varies slightly. In the case below, it's 2 difference. How can I do an "in between" instead of "equals" so I can cover for any minor size discrepancies?
@Mike_S So in this case you don't need the Switch + Variable. You can use an expression in that case. You can delete these actions.
I would recommend temporarily removing the Create File action in your flow. Click on the three dot and select Copy to my clipboard and then delete it. This way you can test the flow to ensure the output of the expression above is correct before you even bother creating the file.
First, we'll need to convert the attachment size from bytes to kb. We'll need to divide the attachment size by 1024 to return the kb value.
Unfortunately, Power Automate turns the expression labels into non-editable labels. Not sure why this is (this wasn't the case before they implemented the new designer).
However, you can access the expression with this trick. Click on the three dots of the Compose action and select Peek Code.
Select the expression which is the text after the @ symbol and before the closing double quote marks. Copy it to your clipboard.
Remove the dynamic content label and click on the expression tab and paste your expression in.
Wrap the expression in a div() function. Place your cursor at the start of your expression by pressing the up arrow key and insert div and an opening bracket.
Go to the end of the expression by pressing the down arrow key and insert a comma and the number 1024 and a closing bracket.
This expression will take the attachment size and convert it to kb. Run a test. Review the outputs.
Add Compose actions to your flow to hold the names of each of the folders you'd like to direct your attachments to based on their size. Using Compose actions for the folder names is optional—however, I recommend this in your case to make it easy to adjust the folder name (should you need to in the future) rather than having to edit the expression.
I've put my actions into a Scope action to make it easy to collapse. This is optional (not required for the flow itself).
Since the Switch action requires an exact match—for this particular scenario I think it would be better to use an expression to set the folder name. We'll be composing an expression with the if() + lessOrEquals() function.
The if() function takes 3 parameters:
The lessOrEquals() function takes two parameters. The value your are checking and
We'll be nesting 3 if() functions + lessOrEquals() function within each other to create the expression. The logic for the expression is as follows:
Tip: Each function needs an opening and closing bracket. Go slow an ensure you are always entering a closing bracket to ensure you aren't missing anything. If you ever have issues and get an alert saying your expression is invalid—throw it into ChatGPT! Sometimes I find it easier to build expressions from the inside out (so I don't forget a bracket). Do whatever works for you.
Additionally to quickly get to the start of the expression: Press the UP arrow key. To get to the end of the expression: Press the DOWN arrow key. Pay attention to the tooltip as it'll bold the text of which parameter of the function you are setting.
Add a Compose action. Click on the Expression tab and insert this expression:
if(lessOrEquals(outputs('Compose_-_Attachment_Size'), 12), outputs('Compose_-_12kb'),
if(lessOrEquals(outputs('Compose_-_Attachment_Size'), 25), outputs('Compose_-_25kb'),
if(lessOrEquals(outputs('Compose_-_Attachment_Size'), 40), outputs('Compose_-_40kb'),
outputs('Compose_-_Default'))))
Depending on how you've named your Compose actions in your flow, you may need to replace the dynamic content references in my expression with the appropriate dynamic content references in yours.
Once the text is highlighted, in the Dynamic content tab and select the appropriate Compose action output.
Run a test. Review the outputs. You can see in my screenshots below the first loop of the Apply to Each action has an attachment that is 8kb, so the output of the folder name is 12kb Folder. The second loop has an attachment that is 15kb and the output of the folder name is 25kb.
Add the Create File action back to your flow. Click on Add an action then click on My clipboard. Select the Create file action.
Replace the variable reference with the output of the compose action above.
Run a test!
Now if you choose to rename your folders, you can edit the Compose actions instead of having to edit the expression.
Hope this helps!
If I helped you solve your problem—please mark my post as a solution ✅. Consider giving me a 👍 if you liked my response! |
That seemed to work perfectly as intended! Thank you so much for taking the time to respond. I especially appreciated the screenshots, as I'm more visual. Thanks again. 🙂
Dear Community Members, We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd. During this period, members will not be able to Kudo, Comment, or Reply to any posts. On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities. What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!
We are excited to announce the Summer of Solutions Challenge! This challenge is kicking off on Monday, June 17th and will run for (4) weeks. The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities. Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”) - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024 Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods. You must enter into each weekly Entry Period separately. How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different. Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers. At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing. Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner. A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random. Individuals will be contacted before the announcement with the opportunity to claim or deny the prize. Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners. Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event. ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE** Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24 17 @Anil_g 7 @ManishSolanki 13 @eetuRobo 5 @David_MA 10 @VishnuReddy1997 5 @SpongYe 9JhonatanOB19932 (tie) @Nived_Nambiar 8 @maltie 2 (tie) @PA-Noob 2 (tie) @LukeMcG 2 (tie) @tgut03 2 (tie) Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate @Deenuji 12@ManishSolanki 19 @Anil_g 10 @NathanAlvares24 17 @VishnuReddy1997 6 @Expiscornovus 10 @Tjan 5 @Nived_Nambiar 10 @eetuRobo 3 @SudeepGhatakNZ 8 Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22 Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2 Anil_g2 SharonS2
On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners. The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights. Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.
We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for. We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer. Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together. Here's to new beginnings and endless possibilities! If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport. To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages