Create / Update ListItem Fields from PowerApps
Sometimes I have to do some Microsoft projects with the Power Platform and more especially with Power Apps. Because I am not a master with it, I spend a considerable time to search some answers π I decided to note all the points about how to create and update SharePoint item fields through a Power Apps application.
Some notes before updating an item
During my Power Apps projects, I noted some behaviors that I did not expect... So, I noticed them here π.
Change the Control Type of a field
When the Control type of a field is changed, the DataCardValue number change at the same time. If some functions use this DataCardValue before changing the Control Type, think to update the DataCardValue number in the function too.
[note]Note
It is not possible to change the "type" of the control (ex: text <> choice). The only way is to delete the existing field and replace it with the new one (if the type has changed on the SharePoint side)
Create an item
The first easiest method to create an item is to use a Form and the SubmitForm()
This method is pretty easy to use and has the advantage to validate the form before sending the request. All fields that return an error will be highlighted with a red border and an error message. The validation of the form takes into account the configuration of the SharePoint list fields.
But, if the submit function is not performed directly on the screen that contains the form, the highlighted fields are not persistent.
Example: a form split into several screens; some fields are mandatory or have some constraints; the final screen performs the submit.
If the user returns to a previous screen to fix the error(s), the specific field(s) in error won't be highlighted.
[Success] Tip
To manage the fields with an error, use a Collection to store the name or internal name of each error field. Then, for each one of them, handle the highlight manually.
The other method consists to use Patch()
. It is not possible to send directly a Form. Each field must be manually specified, and of course, the form won't validate before and you are faced with the same problem for the highlight error fields.
It is possible to check if the form is valid:
or validate each field based on the data source constraints:
Update an item
SubmitForm()
still working to update an item. The prerequisites are:
- FormMode.Edit
- Item must be specified
It is possible to use Patch()
also :
The Update()
methods work in the same way (just replace Patch by Update). The big pro of this method is the Filter()
and SharePoint list with more than 2000 items.
Another alternative is to use UpdateIf()
:
- No filter condition
- Easy to perform several conditions
- Less code for several use cases
It is so possible to create a new item from one form and update this new item with additional fields from another form for example:
Now with this information in mind, let's see how to send data in accordance with the field type.