Vue normale

Il y a de nouveaux articles disponibles, cliquez pour rafraîchir la page.
À partir d’avant-hierFlux principal

How to Select First Item in a Power Apps Gallery

In this Power Apps Tutorial, we’ll look at how to select first item in a Power Apps gallery.

We were recently asked to create a Power Apps gallery that would select the first item when working with the Power Apps canvas apps.

Along with this, we will discuss the below topics based on a select the first item within the Power Apps gallery control. Such as:

  • Power Apps get the first selected item in a gallery
  • Power Apps select the first item in a filtered gallery
  • Power Apps get the first item in a gallery collection

Power Apps select first item in a gallery

In this section, we’ll look at how to select the first item in a Power Apps gallery. That is, the gallery will be displayed by default by selecting the first item.

For this, we need to build a Power Apps gallery. We have a SharePoint list named Hotel Guest Registration that contains different types of columns such as single line of text, date, number, etc as shown below:

Power Apps select the first item in the gallery
Power Apps select the first item in the gallery
  • Using the above SharePoint list, we will create a canvas app within the Power Apps.
PowerApps select the first item in the gallery
PowerApps select the first item in the gallery

Note:

In the above Power Apps gallery, we have concatenated the guest’s first name and last name as well as the address and city by using the below expressions.
  • Now, insert the following expression into the Default property of the Power Apps vertical gallery. As a result, it selects the first item in the gallery by default.
Default = First(Self.AllItems)
Select default first item in Power Apps gallery
Select the default first item in a Power Apps gallery
  • To identify the selected item, insert the below expression on the gallery’s TemplateFill property.
TemplateFill = If(ThisItem.IsSelected, Color.BlanchedAlmond,Color.LightGray)
How to auto select first item in a Power Apps gallery
How to auto-select the first item in a Power Apps gallery

This is how to auto-select the first item in a Power Apps gallery.

Get first selected item in a Power Apps gallery

Here, we will see how to get the first selected item in a Power Apps gallery. For this, we are going to use the above example of the Power Apps gallery where the first item has been selected bydefault.

To get the first selected gallery item, the following steps are:

  • On the Power Apps screen, add a display form where we can display all the details from the Power Apps screen.
  • Insert the below expression on the Items property of the Power Apps display form.
Items = Hotel_Registration_Gallery.Selected

Where Hotel_Registration_Gallery is the name of the Power Apps vertical gallery.

Get selected first gallery item value in Power Apps
Get selected first gallery item value in Power Apps

We can see that the Power Apps display form will show all of the details from the first gallery item that was selected.

Power Apps get the first selected item in a gallery
Power Apps get the first selected item in a gallery

This is how to get the first selected item in a Power Apps gallery.

Also, read How to create multiple tabs form in Power Apps

Power Apps select the first item in a filtered gallery

In this section, we’ll look at how to choose the first item from a filtered Power Apps gallery. That is, we will create a filter gallery based on a specific condition and then identify the first item from the filtered values.

To work with this scenario, we are going to use the above Power Apps gallery and the following steps are:

  • Suppose, we are going to filter the data whose ‘check-in’ date is on 16/3/2023. For this, we will insert the below expression on the gallery’s Items property.
Items = Filter('Hotel Guest Registration','Check-in Date'=Date(2023,3,16))

Where ‘Hotel Guest Registration’ is the name of the SharePoint data source, and ‘Check-in Date’ is the name of the SharePoint list date column based on which we will filter the gallery data.

How to get first selected item from the Power Apps filtered gallery
How to get a first selected item from the Power Apps filtered gallery
  • To get the first selected item from the above Power Apps gallery, update the gallery’s Items property with the below expression:
Items = First(
    Filter(
        'Hotel Guest Registration',
        'Check-in Date' = Date(
            2023,
            3,
            16
        )
    )
)

Also, insert the below expression on the gallery’s TemplateFill property to identify the selected first item.

TemplateFill = If(ThisItem.IsSelected, Color.DarkSalmon,Color.LightGray)
Power Apps get a first selected item in the filtered gallery
Power Apps get a first selected item in the filtered gallery

This is how to get the first selected item in the Power Apps filtered gallery.

Power Apps get the first item in a gallery collection

We’ll look at how to get the first item in a Power Apps gallery collection in this section. As per the requirement, we will display the collection through a gallery and select the first item from it.

We made a collection based on a button control. That is, when the user clicks the button, a collection is created. For this, we have used the below expression on a Power Apps button control’s OnSelect property.

OnSelect = Collect(ColGadgets,
{Gadget:"Airpods Gen 2" , Year: 2022, Manufacturer: "Apple"},
{Gadget:"Meta Quest Pro" , Year: 2023 , Manufacturer: "Meta"},
{Gadget:"Google Pixel 7" , Year: 2022 , Manufacturer: "Google"},
{Gadget:"Watch Ultra" , Year:2023 , Manufacturer: "Apple"},
{Gadget:"G4 electric bike" , Year:2021 , Manufacturer: "Gocycle"},
{Gadget:"Legion Pro 7i Powerful Laptop" , Year:2023 , Manufacturer: "Lenovo"}
);
power apps select first item in a gallery collection
power apps select first item in a gallery collection
  • Next, click on the button to create a collection and add a vertical gallery to the Power Apps screen. Connect the gallery with the collection. As a result, the gallery will display all the collected data.
Power Apps get first selected item in the gallery collection
Power Apps get first selected item in the gallery collection
  • Now, let’s add another gallery to get the first selected item from the above Power Apps gallery collection. For this, insert the below expression on the new gallery’s Items property.
Items = First(ColGadgets)

We can see, the new gallery will display the first selected item from the Power Apps gallery collection as shown below:

How to get first selected item in the PowerApps gallery collection
How to get the first selected item in the PowerApps gallery collection

This is how to get the first selected item in the PowerApps gallery collection.

Conclusion

From this Power Apps Tutorial, we learned all about getting the first selected gallery item within Power Apps based on different scenarios. Such as:

  • Power Apps select the first item in the gallery
  • Power Apps get the first selected item in a gallery
  • Power Apps select the first item in a filtered gallery
  • Power Apps get the first item in a gallery collection

You may like the following Power Apps gallery control articles:

How to Highlight the Selected Item within a Power Apps Gallery?

In this Power Apps Tutorial, we will discuss highlighting a selected item within a Power Apps Gallery.

We recently received a request to work with the selected items of a Power Apps gallery while using the canvas app. Per our client’s request, they want to highlight the item selected within a Power Apps gallery.

Also, we will discuss how to highlight the multi-selected items within the Power Apps gallery.

Highlight the selected item within a Power Apps gallery

Here, we will see how to highlight the selected item within a Power Apps gallery. To achieve this requirement, the following steps are:

  • Let’s build a vertical gallery on the Power Apps screen.
  • Connect the gallery to a data source (Ex: SharePoint, Excel, dataverse table, etc.). Suppose, we have a SharePoint list named Project Management and we have used that list in the Power Apps gallery as shown below:
Power Apps gallery selected item
Power Apps gallery selected item
  • To highlight the particular item or selected item in the Power Apps gallery, insert the following expression on the gallery’s TemplateFill property.
TemplateFill = If(ThisItem.IsSelected, Color.AntiqueWhite, Color.White)

As per the above expression, the selected item will be highlighted as AntiqueWhite and the rest will appear in white.

Highlight the Power Apps selected item
Highlight the Power Apps selected item

This is how to highlight the Power Apps selected item in a gallery control.

Also, Read: How to Patch Dataverse Choice Column in Power Apps

Highlight multi-selected items in the Power Apps gallery

In this section, we will see how to highlight the multi-selected items in the Power Apps gallery.

Currently, we can select only one item in a Power Apps gallery control. But, we can add a temporary Power Apps collection to our app where we will store all the selected items from the gallery.

To achieve this, the followings steps are:

  • We have built a vertical gallery on the Power Apps screen that displays the list of all Office365 users.
    • For this, connect the Power Apps with the Office 365 Users connector. Add a vertical gallery to the Power Apps screen and insert the below expression on the gallery’s Items property. As a result, it will display all the Office 365 users in the Power Apps gallery.
Items = Office365Users.SearchUser()
Power Apps gallery select multiple items
Power Apps gallery selects multiple items
  • Now, we will create a collection that will temporarily store the selected items from the gallery. For this, add the below expression on the Power Apps gallery’s OnSelect property.
OnSelect = If(
    ThisItem.DisplayName in CollSelectedUsers.DisplayName,
    Remove(
        CollSelectedUsers,
        ThisItem
    ),
    Collect(
        CollSelectedUsers,
        ThisItem
    )
)

Where the CollSelectedUsers is the name of the collection that will store the multi-selected items.

Highlight the Power Apps multi selected gallery item
Highlight the Power Apps multi-selected gallery item
  • To identify the selected items, insert the following expression on the TemplateFill of the Power Apps gallery control.
TemplateFill = If(
    ThisItem.DisplayName in CollSelectedUsers.DisplayName,
    Color.AliceBlue,
    Color.White
)
Power Apps Highlight the multi selected gallery items
Power Apps Highlight the multi-selected gallery items
  • To visualize the selected items from the Power Apps gallery, let’s add another vertical gallery to the Power Apps screen.
  • Connect that vertical gallery with the collection that we have created. (i.e., CollSelectedUsers)
Select multiple items in Power Apps gallery
Select multiple items in the Power Apps gallery

That’s it! Let’s publish the app and preview it. we can see when we select the item(s), it will display on another gallery as well as highlight those selected items within the gallery.

Highlight the multi selected gallery item in Power Apps
Highlight the multi-selected gallery item in Power Apps

Similarly, if we deselect the item(s), it will remove from the other gallery as well. This is how to highlight the multi-selected items from the Power Apps gallery.

Additionally, you may like some more Power Apps tutorials:

Conclusion

From this Power Apps tutorial, we learned how to highlight a single selected item as well as multi-selected items within the Power Apps gallery.

How to Display Dataverse Choices in Power Apps Gallery

Do you know how to display Dataverse Choices in Power Apps Gallery Control? Well, in this Microsoft Dataverse tutorial, We will discuss how we can display the Dataverse Choice values (multi-select option set) in a Power Apps Gallery Control.

Also, we will see how to add a Power Apps sub-gallery control inside a main gallery control and display all the Dataverse choices.

Read: Power Apps Get Value Of Choice Field Dataverse

Display Dataverse Choices (multi-select option set) in Power Apps Gallery Control

Here we will see how we can display Dataverse Choices (with a multi-select option set) in a Power Apps Gallery Control.

Scenario:

I have a Dataverse Table named Patient Registrations. This table has a Choice column called Reason (with the multi-select option set). Now I would like to display all the Dataverse choice values in the Power Apps Gallery Control.

Display Dataverse Choices in Power Apps Gallery Control
Display Dataverse Choices in Power Apps Gallery Control

The image below represents the Power Apps Vertical Gallery control with all the Dataverse records. In the gallery, you can see the last section (Reason) is having a Label control with the code below: (On Label’s Text property)

Text = ThisItem.Reason

Where

Reason = Dataverse Choice Column Name

But when I use this above code on the Label’s Text property, I am getting the below error i.e.

This formula uses scope, which is not presently supported for evaluation.

Refer to the screenshot below.

How to Display Dataverse Choices in Power Apps Gallery
How to Display Dataverse Choices in Power Apps Gallery

Follow the steps below that how we can achieve our needs.

Solution:

Step – 1:

First, select your Power Apps Gallery control (Master Gallery) and delete the label control that shows the above error.

How to display Dataverse Choices in Power Apps Gallery Control
How to display Dataverse Choices in Power Apps Gallery Control

Step – 2:

Here we will add a Sub-gallery inside the Master Gallery. Select the first section of the master gallery -> Expand + Insert -> Select Vertical gallery as shown below.

Get Dataverse Choices in Power Apps Gallery
Get Dataverse Choices in Power Apps Gallery

Step – 3:

Drag the child gallery and keep it under the Reason field. The below screenshot represents how the sub-gallery control will look inside the master gallery control. Just rename the sub-gallery control to Child Gallery.

How to get Dataverse Choice options in Power Apps Gallery
How to get Dataverse Choice options in Power Apps Gallery

Step – 4:

Select the Child Gallery -> Go to the Properties tab (from the right side) -> Expand the Layout option and select Title as below.

How to retrieve Dataverse Choices in Power Apps Gallery
How to retrieve Dataverse Choices in Power Apps Gallery

Step – 5:

Next, select the Child gallery control and set its Items property to the code below:

Items = ThisItem.Reason

Where,

Reason = Dataverse Choice Field Name

After applying the above code, you will see the same error message i.e. “This formula uses scope, which is not presently supported for evaluation“.

Retrieve Dataverse Choices in Power Apps Gallery
Retrieve Dataverse Choices in Power Apps Gallery

Step – 6:

To overcome the above issue, select the Title control inside the Child gallery and set its Text property to the code below:

Text = ThisItem.Value

Once you applied the above code, you will not see any error message and at the same time, you will get the appropriate choices for each individual record.

How to get Dataverse Choice values in Power Apps Gallery Control
How to get Dataverse Choice values in Power Apps Gallery Control

Step – 7:

Finally, you can remove or delete the Separator and Next arrow icons from the Child gallery. You can easily delete these two controls by using the Del button in your system. Or you can delete them by using the Delete option (Select the control -> Click -> Delete) (from the left navigation).

Additionally, if you want to give these controls to any other design, you can do so by using properties like Color, Font, Font size, etc.

Get Dataverse Choice values in Power Apps Gallery
Get Dataverse Choice values in Power Apps Gallery

Once everything is done, then the Gallery control will display all the Dataverse choices (multi-option set) like the image below.

How to get Dataverse Choices in PowerApps Gallery
How to get Dataverse Choices in PowerApps Gallery

This is how to display Dataverse Choices in Power Apps Gallery Control.

Furthermore, you may like some more Power Apps and Dataverse tutorials:

In this Microsoft Dataverse tutorial, We discussed how we can display the Dataverse Choice values (multi-select option set) in a Power Apps Gallery Control.

Also, we saw how to insert a Power Apps sub-gallery control inside a main gallery control and display all the Dataverse choices.

CanvasApps: Tip#1 : How to add a Separator to your Gallery!

How to simply add a Separator like below to your custom gallery control?

  1. Go to your Gallery (myGallery) and add a rectangle (mySeparator)

2. set the below properties on the rectangle

X= 2
Y= myGallery.TemplateHeight - mySeparator.Height
Width =  myGallery.TemplateWidth - 2 * mySeparator.X
Height= 2

miraghaly

Add a Location Column to a Site Content Type

Have I ever mentioned how important Content Types are in SharePoint? Almost everything you work with in SharePoint has a Content Type. If you’re just using Document and Item, you’re really not using the platforms.

In this post, I want to talk about Site Content Types and the Location column type.

Location Columns

Sometime in the last few years, we got a cool new type of column we can use in SharePoint. In Microsoft’s infinite wisdom, it’s called either a GeoLocation column or a Location column, depending on where you interact with it. It’s got a lot of magical qualities, but I can’t easily find an end user article about those qualities. Buried in the support article List and library column types and options, you’ll read this:

Add rich location data from Bing Maps or your organization directory. The location column provides additional columns to filter, sort, and search by related information including street address, city, state, country or region, postal code, coordinates, or name.

Site Content Types

Site Content Types are the best kind of Content Types in my book because we can instantiate them across modern sites with Site Templates (nee Site Designs).

Until recently, we couldn’t create a Location column as a Site Column (to add to a Site Content Type) unless we ran the Add-PnPField PnP.PowerShell cmdlet. (See: Add a Geolocation column to a list programmatically in SharePoint) Not exactly the purview of your average information architect.

Today I wondered if this had changed – and it has!

Add a Location Column to a Site Content Type

The big thing that changed recently is that Microsoft is slooowwwlyyy moving us away from the Content Type Hub and into the Content Type Gallery. When the new Content Type Gallery was initially delivered, it was really just lipstick on a pig; it was still the Content Type Hub underneath.

Now when we go into Site Settings on a modern site and click the Site content types link, we land in the Content Type Gallery. This is pretty new, and it’s possible you don’t see it in your tenant yet, though it seems to be in all the tenants where I’m working. In the Content Type Gallery , we can add Site Columns in this new UI with the Location column type.

Let’s say I want to create a Site Content Type called Property. A very normal thing I’d want to know about a Property is its address, and I’d sure like to use a magical Location column type to capture it. Here’s the sequence.

From the home page of your modern site:

Click on the gear

Choose Site information, then View all site settings

On the ugly old Site Settings page, we still see the same old two options in the Web Designer Galleries section:

The difference is now when we click on the Site content types link, we land in the Content Type Gallery.

Once we’re here, we can build the Content Type pretty much like we would in the old UI. It’s basically the same.

The big difference for this post is we can now choose a Location column when we create a new Site Column.

See that Location in the Type column below?

When we go back to the site, we have the Location column, and it’s set up as a Site Column, so we can reuse it, maybe promote it to a Managed Property for search (though I haven’t done this), etc. Even better, we can package up that Property Content Type into a Site Template so we can instantiate it in new sites where we want the same information architecture. This latter step will require some PowerShell, and maybe you shouldn’t run with those scissors. Find a SharePoint Admin to help here.

I did run into one issue. I had already enabled the Property Content Type in a list, and the new Location column wasn’t showing up. Unfortunately, the Update sites and lists option, which we’re used to having checked by default is now NOT checked by default. So you need to be sure to click it EVERY TIME YOU MAKE A CHANGE TO THE CONTENT TYPE if you want that change to cascade down into your list or libraries. I have never unchecked that box in the past, and I consider it a “bug” that the default is unchecked now. At least it’s something we can work around. I hope Microsoft changes this back to the old behavior.

❌
❌