In this Power Apps Tutorial, We will learn how to set a ‘ThisItem‘ operator within the Power Apps. Also, We will discuss how to work with the ThisItem operator within the Power Apps gallery based on different scenarios.
Currently, We got a requirement from one of our clients while working with a certain canvas app. As per their requirement, they want to set a variable value using the ThisItem operator.
Also, Read: How to Select First Item in a Power Apps Gallery
What is Power Apps ThisItem?
In Power Apps, ThisItem is a formula that refers to the currently selected item in a gallery or form control. When a user interacts with a gallery or form control, Power Apps automatically sets the context of ‘ThisItem‘ to the item that was selected.
The Power Apps ThisItem refers to the properties of the currently selected item, such as its ID or name, in formulas and expressions throughout your app. That is, it represents the current data structure for each section of the record within the respective gallery.
Working with the Power Apps ThisItem
Here, we will see how to work with the Power Apps ThisItem operator within a gallery control. For this, the following steps are:
- On the Power Apps screen, add a blank vertical gallery.
- Add a text control to the Power Apps gallery. We can see as the gallery didn’t connect with any data source, it will display a sample text within the text control with the below expression.
Text = ThisItem.SampleText
- Let’s add a button control to the gallery and create a global variable to store the SampleText of each section of the record.
- For this, add a button control to the above Power Apps gallery and insert the below expression on the button’s OnSelect property.
OnSelect = Set(VarValue, ThisItem.SampleText)
- Again, we will add a text input control on the outside of the Power Apps gallery. Insert the below expression on the Text property.
Text = VarValue
Where VarValue is the name of the global variable that we have created. Now, we can see when we click any button the respective item will be displayed on the text input control.
This is how to work with the ThisItem value in Power Apps.
Check out: How to get selected value from gallery in Power Apps?
Set ThisItem value in the Power Apps gallery
Here, we will see how to set a value using the ThisItem operator within a Power Apps gallery. For this, we have a SharePoint list based on ‘Content Scheduler’ having different types of columns such as single line of a text column, choice column, and date as shown below:
On the Power Apps screen, let’s add a blank vertical gallery and connect the gallery with the above SharePoint list.
- Add a text label control to the above Power Apps gallery and insert the below expression on the Text property to display the content’s title.
Text = ThisItem.Title
Once we insert the above formula it retrieves all the data from the title column of the specified SharePoint list.
- Similarly, we can add another text label control to display the date column data. For that, the expression will be as below:
text = ThisItem.'Draft Date'
- In the case of the choice column, the expression will be a little different. For this, add a text label control to the Power Apps gallery and insert the below expression on the Text property to display the blog status value.
Text = ThisItem.'Blog Status'.Value
Similarly, we have added 2 more text label control to add publish date and blog type as shown below:
This is how to set the ThisItem value in a Power Apps gallery.
Have a look: How to add text input to Power Apps collection?
Update ThisItem value in Power Apps gallery
In this section, we will discuss how to update a value in Power Apps gallery using the ThisItem property. That is, we will add an icon to the above Power Apps gallery. When the user clicks on that icon, the respective item’s ‘publish date’ will be updated to a specific date value.
To work with this scenario, the following steps are:
- Add an icon (calendar or right) to the above Power Apps gallery.
- Insert the below expression on the icon’s OnSelect property.
OnSelect = Patch(
'Content Scheduler',
ThisItem,
ContentScheduler_Gallery.Selected,
{'Publish Date': Today()}
)
Where
- ContentScheduler_Gallery is the name of the above Power Apps vertical gallery.
- ‘Publish Date’ is the name of the date column where the date value will be updated.
- Today() reveals the current date.
Let’s publish and preview the app. We can see when we click on any icon the respective date value will be updated within the above gallery.
This is how to update a particular item’s value by using the ThisItem in a Power Apps gallery.
Furthermore, you may like some more Power Apps tutorials:
- Power Automate Dataverse Update Multiple Rows
- How to format a currency column in Power Apps?
- How to Sort a Power Apps Dropdown Control?
- How to Add a Time Picker in the Power Apps Canvas App?
- How to Get Gallery Item By ID in Power Apps
Conclusion
From this Power Apps Tutorial, we learned all about Power Apps ThisItem property based on different scenarios. Such as:
- What is Power Apps ThisItem?
- How to work with the Power Apps ThisItem?
- Set ThisItem value in the Power Apps gallery.
- How to update the ThisItem value in a Power Apps gallery?
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.