Latest Posts

PowerApps refer current item in a gallery


In Power Apps, ThisItem is a keyword that refers to the current item or record in a gallery, form, or other data-bound control. It's used to access and display properties of the current record within the context of the control.

PowerApps – Simple use of ThisItem function

When you bind a gallery to a data source, you can use ThisItem to refer to fields of the current record being displayed.

  1. Set up your data source:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductName: "Laptop", Price: 1000},

        {ProductID: 2, ProductName: "Tablet", Price: 500},

        {ProductID: 3, ProductName: "Monitor", Price: 300}

    )

);

  1. Add a Gallery control and set its Items property:

Products

  1. Add Labels to display product information:
    • Set the Text property of one Label to:

ThisItem.ProductName

    • Set the Text property of another Label to:

"$" & ThisItem.Price

This setup displays the product name and price for each item in the Products collection within the gallery.

PowerApps - Use ThisItem function in Forms

ThisItem is useful in forms to refer to the current record being edited or displayed.

  1. Set up your data source (e.g., a SharePoint list or a collection):

ClearCollect(Employees,

    Table(

        {EmployeeID: 1, Name: "John Doe", Department: "IT"},

        {EmployeeID: 2, Name: "Jane Smith", Department: "HR"}

    )

);

  1. Add an Edit Form control and set its DataSource property:

Employees

  1. Add a Label inside the form and set its Text property:

ThisItem.Name

This displays the name of the employee currently being edited or viewed in the form.

PowerApps - Conditional Formatting in Galleries with ThisItem function

You can use ThisItem to apply conditional formatting to items in a gallery based on specific criteria.

  1. Set up your data source:

ClearCollect(Tasks,

    Table(

        {TaskID: 1, TaskName: "Task 1", DueDate: Today()-1},

        {TaskID: 2, TaskName: "Task 2", DueDate: Today()+2}

    )

);

 

  1. Add a Gallery control and set its Items property:

Tasks

  1. Add a Label to display task names and set its Text property:

ThisItem.TaskName

  1. Set the Color property of the Label to apply conditional formatting:

If(ThisItem.DueDate < Today(), Red, Black)

This changes the text color to red for tasks that are overdue.

PowerApps – Access Nested Records using ThisItem function

If your data source contains nested records, you can use ThisItem to access fields within those nested records.

  1. Set up your data source:

ClearCollect(Departments,

    Table(

        {Department: "IT", Employees: Table({Name: "John Doe"}, {Name: "Jane Doe"})},

        {Department: "HR", Employees: Table({Name: "Jim Brown"}, {Name: "Jake White"})}

    )

);

  1. Add a Gallery control and set its Items property:

Departments

  1. Add a nested Gallery inside the first Gallery to display employees:
    • Set the Items property of the nested Gallery to:

ThisItem.Employees

  1. Add a Label inside the nested Gallery to display employee names and set its Text property:

ThisItem.Name

This setup displays departments in the outer gallery and employees within each department in the nested gallery.

PowerApps – Set variable Using ThisItem function

You can use ThisItem in actions like OnSelect to perform operations based on the current item.

  1. Set up your data source:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductName: "Laptop", Price: 1000},

        {ProductID: 2, ProductName: "Tablet", Price: 500}

    )

);

  1. Add a Gallery control and set its Items property:

Products

  1. Add a Button to each item in the gallery and set its OnSelect property:

Set(SelectedProduct, ThisItem)

  1. Display the selected product details using Labels:
    • Set the Text property of one Label to:

SelectedProduct.ProductName

    • Set the Text property of another Label to:

"$" & SelectedProduct.Price

This sets the selected product to a variable and displays its details outside the gallery.

PowerApps - Use ThisItem with LookUp and Patch Functions

You can use ThisItem in combination with functions like LookUp and Patch to update records based on the current item.

  1. Set up your data source (e.g., a SharePoint list or a collection):

ClearCollect(Inventory,

    Table(

        {ItemID: 1, ItemName: "Laptop", Stock: 10},

        {ItemID: 2, ItemName: "Tablet", Stock: 5}

    )

);

  1. Add a Gallery control and set its Items property:

Inventory

  1. Add a Button to each item in the gallery to restock items and set its OnSelect property:

Patch(Inventory, LookUp(Inventory, ItemID = ThisItem.ItemID), {Stock: ThisItem.Stock + 1})

This button will increase the stock count of the selected item by 1.

PowerApps - Use ThisItem with Dynamic Filtering and Sorting

You can use ThisItem to implement dynamic filtering and sorting within galleries based on user input.

  1. Set up your data source:

ClearCollect(Employees,

    Table(

        {EmployeeID: 1, Name: "John Doe", Department: "IT", Age: 30},

        {EmployeeID: 2, Name: "Jane Smith", Department: "HR", Age: 25},

        {EmployeeID: 3, Name: "Jim Brown", Department: "Finance", Age: 40}

    )

);

  1. Add a Dropdown control (DepartmentDropdown) to filter by department.

Items: Distinct(Employees, Department)

  1. Add a Gallery control and set its Items property:

SortByColumns(

    Filter(Employees,

        DepartmentDropdown.Selected.Result = "All" ||

        DepartmentDropdown.Selected.Result = ThisItem.Department

    ),

    "Age",

    Ascending

)

This will filter the gallery to display employees based on the selected department and sort them by age.


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint