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?
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!
Hi @Aeko ,
Are you aware you selected your own post as the solution?
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
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.
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:
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
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.
WarrenBelz
146,731
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,077
Most Valuable Professional