I have an app that is drawing from multiple Dataverse tables. To unify what needs to be I created collections out of each Table.
I then combine these Collections into one Collection for Sorting, Filtering, Searching, etc., but when it comes to making changes they are all updated to the separate Collections since they are duplicates of the Data Source, and the CombinedCol is strictly used for what I just said and to Control the selection of the other Galleries and so forth.
I am able to Patch the Collections. Text, Choices, LookUp columns, and so on, but when I attempt to Patch back to the actual Datasource I can Patch New entries, but It errors when I attempt to change existing entries.
Here is my test run on a non-production table.
Here is the Collection build.
ClearCollect(
TestProjectsCol,
ShowColumns(
Filter(
'Project Portals','Project Portals (Views)'.'Active Project Portals'
),
"cr577_projectid",
"cr577_projectaddress",
"cr577_projectnotes",
"cr577_projectstatus",
"cr577_Assigned",
"cr577_projectname"
)
);
For now this collection is being Patched from a couple of Text Imputs and a Combo Box.
Here is the Patch that works for adding to one of the Collections:
Patch(
TestProjectsCol,
If(
IsBlank(varPick),
Defaults(TestProjectsCol),
varPick
),
{
cr577_projectnotes: TestNotes.Text,
cr577_projectid: testID.Text,
cr577_projectname: TestName.Text,
cr577_Assigned:TestAssigned2.Selected
}
)
I am using a variable to link the input boxes and control if the inputs show the selected Gallery item or are blank from clicking a button I use to run a UpdateContext({varPick: Blank()}) for entering New entries. The above Patch accounts for if there is data or not by running an If() against varPick.
Now when it comes to Patching back to the Datasource I have tried a few methods.
Here is the current Patch to the Datasource that will only write new entries, but not updates.
Patch(
'Project Portals',
If(
IsBlank(varPick),
Defaults(TestProjectsCol),
varPick
),
{
cr577_projectnotes: TestNotes.Text,
cr577_projectid: testID.Text,
cr577_projectname: TestName.Text,
cr577_Assigned:TestAssigned2.Selected
}
);
Refresh('Project Portals')
I know I am missing something obvious, so any assistance that anyone can render will be much appreciated. Thanks in advance.
Your If() function does not contain an alternate if varPick is not blank. The condition for determining which patch to use should be outside of the patch itself. I arbitrarily chose projectid for the LookUp but any column containing a unique value can be used.
With({patch1:Patch('Project Portals',Defaults(TestProjectsCol),
{
cr577_projectnotes: TestNotes.Text,
cr577_projectid: testID.Text,
cr577_projectname: TestName.Text,
cr577_Assigned:TestAssigned2.Selected
}
),
patch2:Patch('Project Portals',LookUp(TestProjectsCol,cr577_projectid=TextID.Text),
{
cr577_projectnotes: TestNotes.Text,
cr577_projectid: testID.Text,
cr577_projectname: TestName.Text,
cr577_Assigned:TestAssigned2.Selected
}
)
},
ForAll(
TestProjectsCol,
If(
IsBlank(varPick),patch1,
patch2
)
)
)
If varPick is not blank the Datasource should be updated with the contents of the field. VarPick is the variable I am using instead of Gallery.Selected. I have changed the format a little so I will try your solution with that setup since I am having the same issue.
User | Count |
---|---|
253 | |
113 | |
92 | |
48 | |
38 |