Do you know how to retrieve all the collection names or headers in Power Apps? Well, in this Power Apps tutorial, We will discuss how to get collection column names in Power Apps, How to get collection column names in Power Apps from three various data sources, etc.
Additionally, we will see how to display collection column names in a Power Apps Gallery control as well as Power Apps Dropdown control.
Get Collection Column Names in Power Apps
Here, I will show you how to get collection names in Power Apps from three different Data sources. Such as:
- Power Apps Get Collection Column Names from a Collection
- Power Apps Get Collection Column Names from a SharePoint List
- Power Apps Get Collection Column Names from a Dataverse Table
Let’s explore each one of these now.
Power Apps Get Collection Column Names from a Collection
In this section, we will see how to get collection column names from a Power Apps Collection.
- For example, I have a Power Apps Collection named colBlogDetails. This collection has some records including five headers like Blog Title, Blog Website, Publication Date, Assigned to, and Status.
- You can see the code below and how the collection looks like in Power Apps:
// Create a Collection
ClearCollect(
colBlogDetails,
{
BlogTitle: "Power Apps Collection",
BlogWebsite: "SPGuides.com",
PublicationDate: "16/02/2023",
AssignedTo: "Preeti",
Status: "Completed"
},
{
BlogTitle: "Power Apps Dropdown",
BlogWebsite: "EnjoySharePoint.com",
PublicationDate: "18/02/2023",
AssignedTo: "Sonam",
Status: "In Progress"
},
{
BlogTitle: "Create Profile in Salesforce",
BlogWebsite: "SalesforceFAQs.com",
PublicationDate: "20/02/2023",
AssignedTo: "Shivam",
Status: "Pending"
},
{
BlogTitle: "Python Reverse String",
BlogWebsite: "Pythonguides.com",
PublicationDate: "21/02/2023",
AssignedTo: "Arvind",
Status: "Not Started"
},
{
BlogTitle: "Oracle Database Data type",
BlogWebsite: "DatabaseFAQs.com",
PublicationDate: "22/02/2023",
AssignedTo: "Saurabh",
Status: "Not Started"
}
)
Where,
- colBlogDetails = Collection name
- Blog Title, Blog Website, Publication Date, Assigned to, and Status = Collection Column names
NOTE:
The above code I have written on the Button’s OnSelect property as per my need. But also you can write either on the Screen’s OnVisible property or App’s OnStart property.
- Once we will click on the Button (Create Collection & Get Headers), the collection will create and all the values will store inside the Power Apps Collections. Refer to the screenshot below:
- Now to get all the collection names in Power Apps, we can write the code below on the same Button’s OnSelect property as:
// Get Column Names
Set(
varCollectionColumnNames,
Distinct(
Ungroup(
MatchAll(
JSON(
colBlogDetails,
JSONFormat.IgnoreBinaryData
),
"([^""]+?)""\s*:"
).SubMatches,
"SubMatches"
),
Value
)
)
Where,
- varCollectionColumnNames = Variable Name
- colBlogDetails = Collection Name
- Next, to view all the collection column names, we can insert a Power Apps Gallery control and set its Items property to the code below:
Items = varCollectionColumnNames
Where,
varCollectionColumnNames = Variable name that you have created to get all the collection column names
This is how to get collection column names from a Power Apps Collection.
Also Read: How to Detect Text in Dataverse Using AI Builder
Power Apps Get Collection Column Names from a SharePoint List
Here, We will see how to get Power Apps collection column names from a SharePoint list.
- There is a SharePoint list named Employee Onboarding. This list has various columns with different data types. Such as:
- ID, Employee Name, Employee Last Name, Employee ID, Department, Location, etc. Also, this SharePoint list includes some of the default columns like Created, Created By, Modified, etc.
- After that, I’ll create a Power Apps Collection and put all of these column names in it. Following that, I will get every column name from the particular collection.
- To collect the SharePoint List columns, apply the code below on Button’s OnSelect property as:
// Collect the table values
ClearCollect(
colEmpOnboardingDetails,
'Employee Onboarding'
);
Where,
- colEmpOnboardingDetails = Collection Name
- ‘Employee Onboarding’ = SharePoint List Name
NOTE:
Verify that the SharePoint List Datasource connector is required before implementing the above code. If not, you can experience certain issues.
- Now, using the same Button’s OnSelect property, we can write the following code to retrieve all the collection names in Power Apps:
Set(
varListColumnNames,
Distinct(
Ungroup(
MatchAll(
JSON(
colEmpOnboardingDetails,
JSONFormat.IgnoreBinaryData & JSONFormat.IgnoreUnsupportedTypes
),
"([^""]+?)""\s*:"
).SubMatches,
"SubMatches"
),
Value
)
)
Where,
- varListColumnNames = Variable name
- colEmpOnboardingDetails = Collection name that you have created to store all the SharePoint list column names
- & JSONFormat.IgnoreUnsupportedTypes = Unsupported data types are accepted, but they won’t be included in the final result.
IMPORTANT NOTE:
If we will not use this & operator and Power Apps JSONFormat.IgnoreUnsupportedTypes function, then we will get an attachment error that can not not serialized with Power Apps JSON Format.
You can refer this article for more details: The JSON function cannot serialize tables / objects with a nested property called ‘{Attachments}’ of type ‘Table(Attachment)’ Power Apps
- Next, Click on the button (Tap to get SP List Columns) to create the collection and get SharePoint list columns.
- Insert a Power Apps Dropdown control and set its Items property to the following code to display all the SharePoint List column names:
varListColumnNames
Where,
varListColumnNames = Created Variable name
- So the result will appear in the Power Apps dropdown control as shown below.
This is how to get Power Apps collection column names from a SharePoint list.
Check Out: How to Update a Row in Dataverse Using Power Automate
Power Apps Get Collection Column Names from a Dataverse Table
Next comes how we can get Power Apps collection column names from a Dataverse table.
- There is a Dataverse table named Car Booking Details. This table has various columns with different data types. Such as:
- Car Name, Booking Date, Buyer Name, Buyer Contact Number, etc. Also, this dataverse table includes some of the default columns like Created On, Modified On, Version Number, etc.
- After that, I’ll add all of these table column names to a Power Apps Collection that I’ll create. I will then obtain the names of each column in the specific collection.
- Use the following code to collect the Dataverse table columns on the Button’s OnSelect property:
// Collect the table values
ClearCollect(
colCarBookingInfo,
'Car Booking Details'
);
Where,
- colCarBookingInfo = Collection Name
- ‘Car Booking Details‘ = Dataverse Table Name
NOTE:
Verify that the Dataverse connector is required before implementing the above code. If not, you can experience certain issues.
- Now, using the same Button’s OnSelect property, we can write the following code to retrieve all the collection names in Power Apps:
// Get the column headers
Set(
varColumnNames,
Distinct(
Ungroup(
MatchAll(
JSON(
colCarBookingInfo,
JSONFormat.IgnoreBinaryData & JSONFormat.IgnoreUnsupportedTypes
),
"([^""]+?)""\s*:"
).SubMatches,
"SubMatches"
),
Value
)
)
Where,
- varColumnNames = Variable name
- colCarBookingInfo = Collection name that you have created to store all the Dataverse table column names
- & JSONFormat.IgnoreUnsupportedTypes = Unsupported data types are accepted, but they won’t be included in the final result.
IMPORTANT NOTE:
If we will not use this & operator and Power Apps JSONFormat.IgnoreUnsupportedTypes function, then we will get an polymorphic error that can not not serialized with Power Apps JSON Format.
You can refer this article for more details: The JSON function cannot serialize tables / objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’ Power Apps
- Next, Click on the button (Tap to get Dataverse Table Columns) to create the collection and get all the Dataverse table columns.
- Add a Power Apps Dropdown control and set its Items property to the following code to display all the Dataverse table column names:
varColumnNames
Where,
varColumnNames = Created Variable name
- As a result, the outcome will show up in the Power Apps dropdown control as displayed below. Here, the Dataverse table column names (those are custom columns) will appear with the internal name that includes a prefix like crf9a_bookingdate.
This is how to get Power Apps collection column names from a Dataverse table.
Furthermore, you may like some more below Power Apps & Dataverse tutorials:
- Power Apps Button OnSelect [Complete Tutorial]
- PowerApps Count Function with Examples
- How To Remove Commas From Dataverse Number Field
- Dataverse Version History
- How to work with dataverse formula column
- How to Get Power Apps Environment ID
In this Power Apps tutorial, We discussed how to get collection column names in Power Apps, How to get collection column names in Power Apps from three various data sources, etc.
Additionally, we saw how to display collection column names in a Power Apps Gallery control as well as Power Apps Dropdown control.
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com