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?
Many thanks in advance!
Solved! Go to Solution.
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.
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.
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.
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
}
)
)
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.
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?
So what is your formula at this point?
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!
No problem! Happy to help!
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?