ThisRecord

How to Use the Power Fx ThisRecord  Function in Power Apps

In this article, we will explore the ThisRecord function and show you how to use it in your Power Apps applications.

What is the ThisRecord Function?

The ThisRecord function is a Power Fx function that returns the record that is currently displayed in a form or gallery. It allows you to access the values of the fields in the current record and use them in your formulas.

How to Use the ThisRecord Function

To use the ThisRecord function, you first need to have a form or gallery on your screen. The form or gallery should be connected to a data source, such as a SharePoint list or an Excel spreadsheet.

Once you have a form or gallery on your screen, you can add a control, such as a label or a text box, to display the value of a field in the current record. To display the value of a field, you can use the following formula:


ThisRecord.FieldName


Replace FieldName with the name of the field you want to display. For example, if you want to display the value of the Title field, you can use the following formula:


ThisRecord.Title


You can also use the ThisRecord function to set the value of a field in the current record. To set the value of a field, you can use the following formula:


Patch(DataSource, ThisRecord, {FieldName: NewValue})


Replace DataSource with the name of your data source, FieldName with the name of the field you want to update, and NewValue with the new value you want to set.

For example, if you want to update the Title field with a new value, you can use the following formula:


Patch(MyList, ThisRecord, {Title: “New Title”})


Examples

Let's look at some examples of how to use the ThisRecord function in Power Apps.

Example 1: Displaying the Value of a Field

Suppose you have a form that displays information about a customer, including their name and email address. You want to display the customer's name in a label on the screen.

To do this, you can add a label control to the screen and set its Text property to the following formula:


ThisRecord.Name


This will display the name of the customer in the label control.

Example 2: Updating the Value of a Field

Suppose you have a form that allows users to update the status of a task. The form has a drop-down list that allows users to select the new status.

To update the status of the task, you can use the following formula in the OnSelect property of a button control:


Patch(MyTasks, ThisRecord, {Status: Dropdown.Selected.Value})


This formula will update the status of the task with the value selected in the drop-down list.

The ThisRecord function is a powerful tool that allows you to access data from the current record in a form or gallery. It can be used to display the value of a field or update the value of a field. By using the ThisRecord function, you can create custom business applications that automate tasks and create complex workflows.

Power Apps Training Courses by G Com Solutions (0800 998 9248)