Skip to main content

Notifications

Community site session details

Community site session details

Session Id : nt2eOQ0z6eZsyuDM7diCHk
Power Apps - Building Power Apps
Answered

Change data source for an edit form based on gallery selected

Like (0) ShareShare
ReportReport
Posted on 9 Mar 2020 03:00:41 by 6

Hello All,

 

New to  Power Apps. Is there a recommended way to change the data source for an edit or display form depending on what gallery the record was selected from?

 

I have two tables from an excel sheet. TeamA and TeamB. Each team has entries that I want to modify/change the values of in an edit form. I want to use one edit form for both teams but the current issue is that I am only able to give it one data source. I could duplicate the edit form but I can see this becoming inefficient with more than 2 tables.

 

I currently have my edit form Item as 'teamAGallery.Selected' and the data source is tableA. Obviously this works for anything I do to team A but accessing through team B, writes into tableA. Is there a reccomended to deal with multiple data sources based on what 'team' I am accessing the entry from?

Categories:
  • balakowsalya Profile Picture
    15 on 02 Feb 2022 at 15:42:30
    Re: Change data source for an edit form based on gallery selected

    Hi @WarrenBelz / @v-siky-msft  ,

     

    I ran into the same issue that @Aeko  has mentioned but in my case, the data source is Sharepoint lists. I figured out the same solution to dynamically change the data source by storing the current data source to Set variables and update the data.

     

    It is working awesome for the Lists with the same fields, but I have an issue in editing the records for the lists with different fields. I'm not able to choose the data source for the edit/display form because it is taking only the Custom Datacards.

     

    I have different lists with different fields structure and want it to be sourced into the edit/display form for the update.

     

    It would really help me if you can guide me in solving this issue.

     

    Thanks in advance!

  • WarrenBelz Profile Picture
    146,731 Most Valuable Professional on 09 Mar 2020 at 20:01:10
    Re: Change data source for an edit form based on gallery selected

    Hi @Aeko ,

    Are you aware you selected your own post as the solution?

  • Aeko Profile Picture
    6 on 09 Mar 2020 at 16:03:45
    Re: Change data source for an edit form based on gallery selected

    Thanks for the reply. This was very useful, I was not aware of being able to set variables. 

     

    Thank you. I will let you know if this works for me once I try to implement it

     

  • WarrenBelz Profile Picture
    146,731 Most Valuable Professional on 09 Mar 2020 at 06:16:26
    Re: Change data source for an edit form based on gallery selected

    Hi @Aeko,

    and thanks @v-siky-msft  for confirming the principle.

    I have several forms and galleries bound conditionally to different data sources with identical fields (I think 6 is the most) and they work fine. Mostly galleries, but a number are edit forms, which also also work fine on SubmitForm.

     

     

  • Verified answer
    v-siky-msft Profile Picture
    on 09 Mar 2020 at 06:03:02
    Re: Change data source for an edit form based on gallery selected

    Hi @Aeko ,

    PowerApps Form control is not designed for multiple data source, it can only be bound to a single data source.

    If two tables' Column constructs are the same, we can show TableB Item in Form Table A(data source) Form, which means Form data source is Table A, but the Items property can be set as the record form TableB, then we have to use Patch function to save TableB records back to Table B, just think of the Form as a frame.

    Here is my test result:

    GIF_43.gif

    Steps:

    1.Set OnSelect of teamAGallery: Set(Var_SelectedItem,ThisItem);Set(Var_datasource,"TeamA")

    2.Set OnSelect of teamBGallery: Set(Var_SelectedItem,ThisItem);Set(Var_datasource,"TeamB")

    3.Set Form data source: TeamA or TeamB, anyone is ok

    4.Set Form Items property: Var_SelectedItem

    5.Set Save Button OnSelect: 

     

    If(
     Var_datasource="TeamA",Patch(TeamA,LookUp(TeamA,ID=Var_SelectedItem.ID),{ColumnName:DataCardValue1.Text});Refresh(TeamA),
     Var_datasource="TeamB",Patch(TeamB,LookUp(TeamB,ID=Var_SelectedItem.ID),{ColumnName:DataCardValue1.Text});Refresh(TeamB)
    )

     

    Hope this helps.

    Sik

     

     

  • WarrenBelz Profile Picture
    146,731 Most Valuable Professional on 09 Mar 2020 at 03:14:54
    Re: Change data source for an edit form based on gallery selected

    Hi @Aeko ,

    Set a Variable when OnSelect of the Galleries - Gallery A below

    Set(vGallNo,"A")

    On the DataSource of the form (use your table names).

    If(
     vGallNo = "A", 
     TableA, 
     TableB
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,731 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,077 Most Valuable Professional

Leaderboard