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 / Switch Between SP Libr...
Power Apps
Answered

Switch Between SP Libraries as data source for Gallery

(0) ShareShare
ReportReport
Posted on by 7

Hi,

 

I have several teams that use the same app, with libraries in SharePoint for each team.

The team name is identified when the app starts, I want to use this to change the source for the gallery to the Library for the assigned team.

I have tried to use the switch function, but it does not seem to expose the same data as what is exposed when I enter the library name manually.

Can this be done?

 

Thanks

Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    69,547 Most Valuable Professional on at

    Connectors are hard coded to the libraries that get data from based on the authentication at the time they were created.  As a result there is no way to switch the connector from one library to another dynamically.  Your only choice would be to create separate connectors for each library you need to be able to connect to and select the specific connection object you want to use in the program.  But that's not a very feasible design because of all the overhead required.

     

    Instead I suggest building the app using one data source. Then use either Export or Save As to make copies of the app and edit each to change the data source to the right library.

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @JamesTheGray2 

    Swapping datasources on a control in PowerApps is usually not a good thing.

    You can do this in a couple of ways:

    1) Shape the data signature from each datasource to match a common set of columns that you NEED for your Gallery.  For example, if you only are displaying 5 columns in your Gallery, and these are "common" between all of the libraries, then you can implement a Switch statement, but you need to switch between "Shaped" datasource - meaning that you need to use a ShowColumns function on your datasources to specify the exact same columns for each source that you want.

    ex.

    Switch(someCondition,
     "conditionA",
     ShowColumns(source1, "ID", "FineName", "Title", "Created"),
     "conditionB",
     ShowColumns(source2, "ID", "FineName", "Title", "Created"),
     "conditionC",
     ShowColumns(source3, "ID", "FineName", "Title", "Created"),
    etc..
    )

    (You can also simplify that by just switching on the data source, but you get the point).

     

    2) Provide a Gallery for each list in your App.  Then use a switch statement on the visible property of the Gallery to only display the one you want for that team/user.

     

    Keep in mind...(for #1) if you want to implement an EditForm for any reason, do not use the .Selected of the Gallery as the signature of the record will not match.  You will need to lookup the record.  BUT...there is no such workaround for Forms in regard to the DataSource.  So you would need a form for each library - again, if you need such functionality.

     

    I hope this is helpful for you.

  • JamesTheGray2 Profile Picture
    7 on at

    Thanks for the reply.

    The libraries are all set as connectors in the App already.

    Ideally. I will not have to maintain 9 different apps, creating a separate app for each team seems like it would be burdensome on whoever has to implement any changes or updates.

    Changing connectors isn't the issue, I want to change the data source for the gallery based on the user team name which is stored in a variable on app start.

     

  • Pstork1 Profile Picture
    69,547 Most Valuable Professional on at

    @RandyHayes has the procedure, but as he says its normally not a recommended approach.

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 474

#1
Valantis Profile Picture

Valantis 474

#3
WarrenBelz Profile Picture

WarrenBelz 375 Most Valuable Professional

Last 30 days Overall leaderboard