web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Clearcollect to only r...
Power Apps
Answered

Clearcollect to only return column headers of a SharePoint list

(0) ShareShare
ReportReport
Posted on by 26

I am using the following code to retrieve certain columns from my list. If I comment out the 'Clear' function at the bottom, it returns all columns including data.

 

When I uncomment the 'clear' function, it deletes everything including the column headers. How do I retrieve only column names from my sharepoint list and then populate that collection at runtime?

 

ClearCollect(
ColTaskUpdates,
ShowColumns(('HelpDesk'),
"Title",
"Description",
"Status",
"Priority",
"AssignedTo",
"Category",
"ResolutionSummary",
"Comments"
)
);

Clear(ColTaskUpdates)

Categories:
I have the same question (0)
  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @Grantx - you can configure the sample expression below to return the column headers of a SharePoint list:

     

    //Create a collection
    ClearCollect(
    myCollection,
     DropColumns(
     'Sample Data',
     "{Attachments}"
     )
    );
    // Get column names
    Set(
     myJSON,
     Distinct(
     Ungroup(
     MatchAll(
     JSON(
     myCollection,
     JSONFormat.IgnoreBinaryData
     ),
     "([^""]+?)""\s*:"
     ).SubMatches,
     "SubMatches"
     ),
     Value
     )
    )
    

     

    I am not clear on your comment re populating the Collection at runtime, because that is the purpose of the ClearCollect function. It will remove the data in the Collection with Clear, and then repopulate the Collection with data using Collect.

     

    ------------------------------------------------------------------------------------------------------------------------------

     

    If I have answered your question, please mark your post as Solved. Remember, you can accept more than one post as a solution.

    If you like my response, please give it a Thumbs Up.

    Imran-Ami Khan

  • Grantx Profile Picture
    26 on at

    Thanks for your reply. Unfortunately that doesn't work. That pulls the entire table and all contents same as the ClearCollect command.

  • Verified answer
    Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @Grantx that's probably because you're not looking at myJSON (which returns a Table of your data source column headers across rows).

     

    You can create a Blank Collection, but not an Empty Collection with e.g.:

     

    Collect(
     myBlankCollection,
     Defaults('HelpDesk')
    );

     

    ------------------------------------------------------------------------------------------------------------------------------

     

    If I have answered your question, please mark your post as Solved. Remember, you can accept more than one post as a solution.

    If you like my response, please give it a Thumbs Up.

    Imran-Ami Khan

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 356 Most Valuable Professional

#2
11manish Profile Picture

11manish 225 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 211

Last 30 days Overall leaderboard