Skip to content

Mohammed Khaled

Patch Function im PowerApps

Estimated reading time: 4 minutes

PowerApps Patch Function Explained

The Patch function in PowerApps is used to update specific fields in a record in a data source, such as a SharePoint list or a SQL table.

The function takes two main arguments: the data source and the record to update, along with the fields and their new values.

Here’s an example of how to use the Patch function to update a record in a SharePoint list:

Patch(
SharePointList,
Defaults(SharePointList),
{Title: “New Title”, Description: “New Description”}
)

In this example, the Patch function is updating the Title and Description fields of the first record in the SharePointList data source to “New Title” and “New Description”, respectively.

The Defaults function is used to specify the record to update, in this case the first record in the list.

The Patch function can also be used in conjunction with other functions, such as the UpdateContext or Collect functions, to update multiple records or to update a record based on user input.

It’s important to keep in mind that if you don’t set the primary key of the record, the patch function will create a new record instead of updating the existing one.

Additionally, you can also use the Patch function to update the records in the collection, for example

Patch(
collData,
First(Filter(collData, columnName = “some value”)),
{columnName: “new value”}
)

This will update the first record in the collection “collData” where columnName = “some value” and change the value of columnName to “new value”.

Examples

Formulas are a key feature in PowerApps that allow you to perform calculations and make logical comparisons on data.

They can be used to create custom expressions, validate data inputs, and control the behavior of app components.

Formulas can be used in various places throughout PowerApps, such as in the properties of controls, in the conditions of rules, and in the behavior of buttons.

The syntax of a formula in PowerApps is similar to that of a spreadsheet formula, and it uses a combination of functions, operators, and values to produce a result.

Functions are predefined formulas that perform specific tasks, such as calculating the sum of a set of numbers or converting a text string to uppercase.

Operators are used to perform mathematical and logical operations, such as addition, subtraction, and comparison.

Values can be numbers, text, true/false, and more.

here are some examples of how to use formulas in PowerApps:

SUM(Filter(OrderItems, OrderID = SelectedOrder.ID), Price)

To calculate the total cost of an order, you can use the SUM function to add up the prices of all items in a collection.

This formula will filter the OrderItems collection to only include items with the same OrderID as the selected order, and then sum the Price field of all those items.

If(ISBLANK(TextInput.Text), “Please enter a value”, “Valid input”)

To check if a text input is blank, you can use the ISBLANK function.

This formula will check if the text entered in the TextInput control is blank. If it is, the formula will return “Please enter a value”, otherwise it will return “Valid input”.

FORMAT(Today(), “yyyy-MM-dd HH:mm”)

To display the date and time in a specific format, you can use the FORMAT function.

This formula will format the current date and time to show the year, month, day, hour and minutes.

If(Toggle1.Value, Set(var, “on”), Set(var, “off”))

To set the value of a variable based on the value of a toggle control

This formula will check the value of the toggle1, if it is on, it will set the value of the variable ‘var’ to ‘on’ else it will set the value to ‘off’.

If(Dropdown1.Selected.Value = “Option1”, true, false)

To set the Visibility of a control based on the selected item in a dropdown

This formula will check the selected value of the Dropdown1 and if it is equals to “Option1” it will set the visibility of the control to true else it will set to false.


Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!