cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ardak2
Helper II
Helper II

Urgent help requested - Sending multiple attachment to flow work, no attachment or less than 5 attachment creates error

Hello,

 

I have a power app that sends attachments to the power automate flow and flow emails the items. Below is the syntax work like charm.

 

But if I dont add any attachments, or add less than 5 attachments, then power app gives error message and does NOT even send anything to flow. Flow does not event initiate. If I add 5 attachments though, it works perfectly fine. Please see attached two screen shots. Here is the working syntax when all 5 attachments are added.

 

My leadership is pressing. Can you please help me? @Pstork1 

@WarrenBelz @iAm_ManCat @LaurensM @Amik 

 

 

 

Set(
    flowResult,
    'PowerApp_UpdatePRNumber-Status'.Run(
        Gallery1.Selected.'Tracker Name',
        Gallery1.Selected.ID,
        Update_Flow_PR_Number,
        Update_Flow_PR_Status.Selected.Value,
        Gallery1.Selected.CO,
        User().Email,
        Text(Gallery1.Selected.'Project Number') & " " & Text(Gallery1.Selected.'Requirement Name'),
        {
            file: {
                contentBytes: Index(Attachments1.Attachments,1).Value,
                name: "PR1.pdf"
            },
            file_1: {
                contentBytes: Index(Attachments1.Attachments,2).Value,
                name: "PR2.pdf"
            },
            file_2: {
                contentBytes: Index(Attachments1.Attachments,3).Value,
                name: "PR3.pdf"
            },
            file_3: {
                contentBytes: Index(Attachments1.Attachments,4).Value,
                name: "PR4.pdf"
            },
            file_4: {
                contentBytes: Index(Attachments1.Attachments,5).Value,
                name: "PR5.pdf"
            }
        }
    ).result
);
// Show the notification based on the value of 'flowResult'
If(
    flowResult = "Success! PR is updated.",
    Notify(
        flowResult,
        NotificationType.Success
    ),
    Notify(
        flowResult,
        NotificationType.Error
    )
);
ClearCollect(
    flowdata1,
    PowerApp_Getitems_Tracker_PKA.Run()
);
Collect(
    flowdata1,
    PowerApp_Getitems_Tracker_PKB.Run()
);
Collect(
    flowdata1,
    PowerApp_Getitems_Tracker_PKC.Run()
);
// Clear the attachments
Reset(Attachments1)

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Pstork1
Most Valuable Professional
Most Valuable Professional

If you are using the attachment control directly then you are correct that the code I provided won't work. The only other way I can think of to do it would be to get the number of actual attachments in the control using CountRows(Attachment1.Attachments) and then use that value in a Switch statement so you can control how many files you actually input.  If the files are marked in the flow as optional parameters that should work, But that would be a very long piece of code.  Something like this, but with all your other paramters as well.

 

UpdateContext({Count: CountRows(Attachments1.Attachments)});
Switch(
    Count,
    0,
       'PowerApp_UpdatePRNumber-Status'.Run(),
    1,
    'PowerApp_UpdatePRNumber-Status'.Run({file: {
                contentBytes: Index(Attachments1.Attachments,1).Value,
                name: "PR1.pdf"
            }}),
    1,
    'PowerApp_UpdatePRNumber-Status'.Run({
            file: {
                contentBytes: Index(Attachments1.Attachments,1).Value,
                name: "PR1.pdf"
            },
            file_1: {
                contentBytes: Index(Attachments1.Attachments,2).Value,
                name: "PR2.pdf"
            }
            }),
    2,
    'PowerApp_UpdatePRNumber-Status'.Run(...,
    3,
    'PowerApp_UpdatePRNumber-Status'.Run(...
)

 



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

View solution in original post

9 REPLIES 9
Pstork1
Most Valuable Professional
Most Valuable Professional

Instead of passing the attachments individually I would pass the collection of attachments as a JSON array and then unpack them in the flow using Parse JSON.  Like this.

'PowerApp_UpdatePRNumber-Status'.Run(
        Gallery1.Selected.'Tracker Name',
        Gallery1.Selected.ID,
        Update_Flow_PR_Number,
        Update_Flow_PR_Status.Selected.Value,
        Gallery1.Selected.CO,
        User().Email,
        Text(Gallery1.Selected.'Project Number') & " " & Text(Gallery1.Selected.'Requirement Name'),
        JSON(Gallery1.Selected.Attachments,JSONFormat.Compact));

The file array is then passed as a Text String.  But after using Parse JSON you can access each file in an Apply to each loop or via Index.



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

Hello Sir, @Pstork1 

 

Please see attached screenshots. The syntax is not accepted by the system. I added both updated app and flow, per your instruction, screenshots for your review. Just to note that the attachments are not part of the gallery as they are not brough from the collection, rather I added them to attachments control (named Attachments1) and send it to flow to send an email. This issue happened right after we published to customers, so I really need to fix it now or my two months of work will look like failure at the onset. Thank you so much

Pstork1
Most Valuable Professional
Most Valuable Professional

If you are using the attachment control directly then you are correct that the code I provided won't work. The only other way I can think of to do it would be to get the number of actual attachments in the control using CountRows(Attachment1.Attachments) and then use that value in a Switch statement so you can control how many files you actually input.  If the files are marked in the flow as optional parameters that should work, But that would be a very long piece of code.  Something like this, but with all your other paramters as well.

 

UpdateContext({Count: CountRows(Attachments1.Attachments)});
Switch(
    Count,
    0,
       'PowerApp_UpdatePRNumber-Status'.Run(),
    1,
    'PowerApp_UpdatePRNumber-Status'.Run({file: {
                contentBytes: Index(Attachments1.Attachments,1).Value,
                name: "PR1.pdf"
            }}),
    1,
    'PowerApp_UpdatePRNumber-Status'.Run({
            file: {
                contentBytes: Index(Attachments1.Attachments,1).Value,
                name: "PR1.pdf"
            },
            file_1: {
                contentBytes: Index(Attachments1.Attachments,2).Value,
                name: "PR2.pdf"
            }
            }),
    2,
    'PowerApp_UpdatePRNumber-Status'.Run(...,
    3,
    'PowerApp_UpdatePRNumber-Status'.Run(...
)

 



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

Dear Sir, @Pstork1  (Just one more small help for connected flow)

 

You are fabulous, without your help, I could not have figured this out.  I will need one more help. So the code you provided perfectly sends data to the flow. I get attachment and append it to and array and have array as email attachment. But i could not get more than one attachment to be appended to same variable. Please see attached. Also, although one attachment works and sends the attachment (pdf) comes blank.

so i need to

1-fix the attachment (pdf) being blank issue

2-append variable for all 5 attachment and if any of the attachment field is empty, do not error, just skip.

 

Thank you so much. @Pstork1 

 

 

 

ardak2
Helper II
Helper II

And here is the complete flow Sir. With zoom in, you can see all steps. Again this perfectly work along with your powerapp code. All I need a way to append all 5 attachments to the array variable, but if any of them dont have value just skip. Thank you so so much @Pstork1 

Pstork1
Most Valuable Professional
Most Valuable Professional

Since the attachments aren't in an array you need to handle each one individually.  So the easiest way is to test each file as you append it to the array to make sure its not null before appending it.  There is no way to send the files as an array other than sending them as a JSON string, which is what I was trying, but that won't work in this case.



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

As I mentioned in my previous reply the files need to be added to the array variable in the flow individually.  Since they aren't passed as an array from the Power App there is no way to handle them in a loop in the flow.  Basically you need to test each file to make sure its not null and then append that file to the array.  Once you've appended all five (or as many as aren't null) then you can proceed with the email.



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

@Pstork1  Sir, eternal thanks for helping. Such a great public support. Best 

ardak2
Helper II
Helper II

Copy of fully working syntax for those who may have same problem. Thanks to @Pstork1 

UpdateContext({Count: CountRows(Attachments1.Attachments)}); 

Switch( 

    Count, 

    0, 

       Set( 

    flowResult, 

    'PowerApp_UpdatePRNumber-Status'.Run( 

        Gallery1.Selected.'Tracker Name', 

        Gallery1.Selected.ID, 

        Update_Flow_PR_Number, 

        Update_Flow_PR_Status.Selected.Value, 

        Gallery1.Selected.CO, 

        User().Email, 

        Text(Gallery1.Selected.'Project Number') & " " & Text(Gallery1.Selected.'Requirement Name') 

    ).result) 

, 

    1, 

        Set( 

    flowResult, 

    'PowerApp_UpdatePRNumber-Status'.Run( 

        Gallery1.Selected.'Tracker Name', 

        Gallery1.Selected.ID, 

        Update_Flow_PR_Number, 

        Update_Flow_PR_Status.Selected.Value, 

        Gallery1.Selected.CO, 

        User().Email, 

        Text(Gallery1.Selected.'Project Number') & " " & Text(Gallery1.Selected.'Requirement Name'), 

        { 

            file: { 

                contentBytes: Index(Attachments1.Attachments,1).Value, 

                name: Index(Attachments1.Attachments,1).Name 

            } 

        } 

    ).result) 

, 

    2, 

        'PowerApp_UpdatePRNumber-Status'.Run( 

        Gallery1.Selected.'Tracker Name', 

        Gallery1.Selected.ID, 

        Update_Flow_PR_Number, 

        Update_Flow_PR_Status.Selected.Value, 

        Gallery1.Selected.CO, 

        User().Email, 

        Text(Gallery1.Selected.'Project Number') & " " & Text(Gallery1.Selected.'Requirement Name'), 

        { 

            file: { 

                contentBytes: Index(Attachments1.Attachments,1).Value, 

                name: Index(Attachments1.Attachments,1).Name 

            }, 

            file_1: { 

                contentBytes: Index(Attachments1.Attachments,2).Value, 

                name: Index(Attachments1.Attachments,2).Name 

            } 

        } 

        ), 

    3, 

       Set( 

    flowResult, 

    'PowerApp_UpdatePRNumber-Status'.Run( 

        Gallery1.Selected.'Tracker Name', 

        Gallery1.Selected.ID, 

        Update_Flow_PR_Number, 

        Update_Flow_PR_Status.Selected.Value, 

        Gallery1.Selected.CO, 

        User().Email, 

        Text(Gallery1.Selected.'Project Number') & " " & Text(Gallery1.Selected.'Requirement Name'), 

        { 

            file: { 

                contentBytes: Index(Attachments1.Attachments,1).Value, 

                name: Index(Attachments1.Attachments,1).Name 

            }, 

            file_1: { 

                contentBytes: Index(Attachments1.Attachments,2).Value, 

                name: Index(Attachments1.Attachments,2).Name 

            }, 

            file_2: { 

                contentBytes: Index(Attachments1.Attachments,3).Value, 

                name: Index(Attachments1.Attachments,3).Name 

            } 

        } 

    ).result) 

, 

    4, 

      Set( 

    flowResult, 

    'PowerApp_UpdatePRNumber-Status'.Run( 

        Gallery1.Selected.'Tracker Name', 

        Gallery1.Selected.ID, 

        Update_Flow_PR_Number, 

        Update_Flow_PR_Status.Selected.Value, 

        Gallery1.Selected.CO, 

        User().Email, 

        Text(Gallery1.Selected.'Project Number') & " " & Text(Gallery1.Selected.'Requirement Name'), 

        { 

            file: { 

                contentBytes: Index(Attachments1.Attachments,1).Value, 

                name: Index(Attachments1.Attachments,1).Name 

            }, 

            file_1: { 

                contentBytes: Index(Attachments1.Attachments,2).Value, 

                name: Index(Attachments1.Attachments,2).Name 

            }, 

            file_2: { 

                contentBytes: Index(Attachments1.Attachments,3).Value, 

                name: Index(Attachments1.Attachments,3).Name 

            }, 

            file_3: { 

                contentBytes: Index(Attachments1.Attachments,4).Value, 

                name: Index(Attachments1.Attachments,4).Name 

            } 

        } 

    ).result) 

, 

    5, 

       Set( 

    flowResult, 

    'PowerApp_UpdatePRNumber-Status'.Run( 

        Gallery1.Selected.'Tracker Name', 

        Gallery1.Selected.ID, 

        Update_Flow_PR_Number, 

        Update_Flow_PR_Status.Selected.Value, 

        Gallery1.Selected.CO, 

        User().Email, 

        Text(Gallery1.Selected.'Project Number') & " " & Text(Gallery1.Selected.'Requirement Name'), 

        { 

            file: { 

                contentBytes: Index(Attachments1.Attachments,1).Value, 

                name: Index(Attachments1.Attachments,1).Name 

            }, 

            file_1: { 

                contentBytes: Index(Attachments1.Attachments,2).Value, 

                name: Index(Attachments1.Attachments,2).Name 

            }, 

            file_2: { 

                contentBytes: Index(Attachments1.Attachments,3).Value, 

                name: Index(Attachments1.Attachments,3).Name 

            }, 

            file_3: { 

                contentBytes: Index(Attachments1.Attachments,4).Value, 

                name: Index(Attachments1.Attachments,4).Name 

            }, 

            file_4: { 

                contentBytes: Index(Attachments1.Attachments,5).Value, 

                name: Index(Attachments1.Attachments,5).Name 

            } 

        } 

    ).result) 

); 

// Show the notification based on the value of 'flowResult' 

If( 

    flowResult = "Success! PR is updated.", 

    Notify( 

        flowResult, 

        NotificationType.Success 

    ), 

    Notify( 

        flowResult, 

        NotificationType.Error 

    ) 

); 

ClearCollect( 

    flowdata1, 

    PowerApp_Getitems_Tracker_PKA.Run() 

); 

Collect( 

    flowdata1, 

    PowerApp_Getitems_Tracker_PKB.Run() 

); 

Collect( 

    flowdata1, 

    PowerApp_Getitems_Tracker_PKC.Run() 

); 

// Clear the attachments 

Reset(Attachments1) 

 

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!      

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Community Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Top Solution Authors
Top Kudoed Authors
Users online (3,896)