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

Notifications

Announcements

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
    68,717 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,297 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
    68,717 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard