Patch is the Swiss army knife for updating data in SharePoint. You need to specify which record you wish to update. Different methods are then possible.
Table of contents
The basic
The easiest way to update a record is as follows
Patch(
Books,
Lookup(Books, ID = 1),
{
DisplayName:"Marcel Proust",
Information:"20th-century writer"
}
)
In this example, we search for the recordset with ID 1 and then update the fields.
The other fields in the SharePoint list will not be updated.
How to get a recordset
Patch From a gallery with Selected Item
We retrieve the selected line from gallery
Patch(
Books,
galBooks.Selected, // Selected Line from our Gallery galBooks
{
DisplayName:"Voltaire",
Information:"Writer"
}
)
Patch From a gallery with a UpdateContext variable
We add a button on the lines of our gallery with the following formula in the OnSelect method
UpdateContext({bookSelected:ThisItem})
The formula is as follows
Patch(
Books,
bookSelected,
{
DisplayName:"Voltaire",
Information:"Writer"
}
)
Patch By Id
To modify a sharepoint item by its ID, we use the Lookup function. With Lookup, we search for the record by ID
Patch(
Books,
LookUp(Directory, ID =1),
{
DisplayName:"Voltaire",
Information:"Writer"
}
)