cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MNik
Helper I
Helper I

Using both form and gallery to create new rows in sharepoint

I am trying to create a form that a user can select multiple values on the same form, then when rows are created in Sharepoint, a new row is created for value, with the form data captured on each row.  

 

I have everything working as intended, however, I am having issues getting the data loaded in Sharepoint.  The error is telling me that a "Title" is required.  I suspect that I have my ForAll and Patch function incorrectly written and that it might not be capturing the form data.  

 

Here is what I have.  Any suggestions on how I can fix it?

 

MNik_0-1665168348629.png

 

Many thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@MNik 

Yes, it is HIGHLY unfortunate that almost all people doing videos and blogs completely misunderstand how the ForAll function works!  This is because someone long ago figured it was like a For Loop and found they could "kind of" make it work that way...and thus the misunderstanding proliferated!

Even the Docs have put some of this bad advice in them.  It is really a shame because the ForAll function is one of the most powerful Data Shaping functions in PowerApps...and with PowerApps, it is all about data shaping!

 

 

So, for your submit button...it should ONLY be:

SubmitForm('Contact Info');

Never put anything after that as you have only issued a "submit".  This happens in the background.  The app does not wait for it to finish.  Plus, you have no idea right after it if it submitted without any error.

This is what the OnSuccess and the OnFailure actions on the form are designed for.

 

So, your OnSuccess action of the 'Contact Info' form should be where you put the Patch and ForAll table.

And it should be:

Patch('Internal Aftersales Part Request',
    ForAll(Requested,
        {
            'Part Number Requested': Col_PartNumberRequested_Column4,
            'Quantity Needed': Col_Qty_Column2
        }
    )
)

It is the Requested that you want to iterate over on the ForAll and it is the 'Internal Aftersales Part Request' that you want to patch...not the other way around that you had in your response.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

9 REPLIES 9
RandyHayes
Super User
Super User

@MNik 

To start, your formula has the ForAll backward. You are trying to use it like a ForLoop in some development language - which PowerApps is not.  ForAll is a function that returns a table of records based on your iteration table and record schema.

It is more efficient to use the function as intended and will provide better performance.

 

Next, if you have a form, then you should be using the SubmitForm function to submit your actual form.  If you need additional records created, this should be done in the OnSuccess action of the form.

 

Next, you are referencing Controls in your formula and not properties of those controls.  So, for example, if NameInput is a text input, then you should be referencing NameInput.Text for the proper values.

 

Finally, and in regard to the second point above...when in your OnSuccess action formula, you can reference Self.LastSumbit.<columnName> to get the values you want that were part of the form.

You should never reference the controls in the form after any submitting as they are not guaranteed to be the same at that point.  But, Self.LastSumbit will always contain the last record submitted in full.

 

So just to provide an example.  Your formula would look more like this:

Patch('Internal Aftersales Part Request',
    ForAll(Requested,
        {Title: Self.LastSubmit.Title, 
         Timestamp: Self.LastSubmit.Timestamp,
         ...etc...
        }
    )
)

 

Not sure what "Requested" is in your formula, but I am assuming that is a table of records.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hi Randy, 

 

First off, thank you for your help.  My apologies as I am new to PowerApps, but I think I am a little bit lost now.  I had watched a few YouTube videos and they showed writing the ForALL/Patch function as I had it above. 

 

The 'Requested' is a collection that I created to capture the requested part numbers and qtys in the gallery.  The form name is 'Contact Info'

 

So for my submit button, I should be using the SubmitForm('Contact Info') command, correct?

 

Then when it comes to submitting the gallery with the form, I tried re-writing using your provided Patch/ForAll command but I wasn't able to get it to work.  Here is a a picture of my app, and hopefully a clearer description of what I am trying to do.  

 

MNik_0-1665412865879.png

 

The red box is the form created from my SP list, the blue box is the gallery attached to the 'Requested" collection that I made to allow for multiple selections if necessary, and the green are fields from the SP list that are not attached to the form but are placed to allow for the selection entry in the gallery.  

 

What I am trying to do is have the the app write a new entry to the sharepoint list for each selection in the gallery like this

contact info + first part/qty selected

contact info + second part/qty selected

contact info + third part/qty selected

 

Here is how my submit button OnSelect function is currently written.  I am currently getting an error stating the data source supplied to the function is invalid.

 

 

SubmitForm('Contact Info');
Patch(
    Requested,
    ForAll(
        'Internal Aftersales Part Request',
        {
            'Part Number Requested': Col_PartNumberRequested_Column4,
            'Quantity Needed': Col_Qty_Column2
        }
    )
)

 

 

 

RandyHayes
Super User
Super User

@MNik 

Yes, it is HIGHLY unfortunate that almost all people doing videos and blogs completely misunderstand how the ForAll function works!  This is because someone long ago figured it was like a For Loop and found they could "kind of" make it work that way...and thus the misunderstanding proliferated!

Even the Docs have put some of this bad advice in them.  It is really a shame because the ForAll function is one of the most powerful Data Shaping functions in PowerApps...and with PowerApps, it is all about data shaping!

 

 

So, for your submit button...it should ONLY be:

SubmitForm('Contact Info');

Never put anything after that as you have only issued a "submit".  This happens in the background.  The app does not wait for it to finish.  Plus, you have no idea right after it if it submitted without any error.

This is what the OnSuccess and the OnFailure actions on the form are designed for.

 

So, your OnSuccess action of the 'Contact Info' form should be where you put the Patch and ForAll table.

And it should be:

Patch('Internal Aftersales Part Request',
    ForAll(Requested,
        {
            'Part Number Requested': Col_PartNumberRequested_Column4,
            'Quantity Needed': Col_Qty_Column2
        }
    )
)

It is the Requested that you want to iterate over on the ForAll and it is the 'Internal Aftersales Part Request' that you want to patch...not the other way around that you had in your response.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thank you for that explanation.  

 

Upon pressing the submit button I am getting the first row to write in SP, but it is not writing in the Part Number Requested or Quantity Requested fields.  

 

I am also receiving a runtime error that Title field is required.  I believe that the error is happening for the subsequent rows after the first row. 

I was able to get the part number and qty's to write to the sharepoint list.  It is creating new lines for each part/qty, however, it is creating the part/qty below the line where the form data is written.  Is it possible to have all of the data written on each line?

 

MNik_0-1665519261708.png

 

RandyHayes
Super User
Super User

@MNik 

So what is your formula at this point?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Nevermind the last request, the project lead likes the way it is currently formatted in SP. 

 

Randy, thank you for your help.  It is always much appreciated! 

RandyHayes
Super User
Super User

@MNik 

No problem!  Happy to help!

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hi Randy, 

 

Circling back around on this one.  The project lead would like to have the form data written to each line with each collection item.  Currently OnSuccess action for the form is written like this:

 

Patch(
    'Internal Parts Request Tracker',
    ForAll(
        Requested,
        {
            'Part Number Requested': col_PartNumberRequested.Number,
            'Quantity Needed': col_Qty.Text
        }
    )
);
Navigate('Success Screen')


Here is the OnSelect button that I am using to add pn's and qty's to my collection:

 

Collect(
    Requested,
    {
        col_PartNumberRequested: cmb_PartNumber.Selected,
        col_Qty: txt_Qty
    }
)

 

Would I need to adjust my collect function to include the items from the form and have it all write to the SharePoint list?

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 (2,660)