cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ameeru18
Frequent Visitor

Saving an Updated Collection back to Dataverse Table

Hello community,

 

I have an App utilizing several Dataverse Tables.

The DV tables are pulled into filtered collections. One collection has parts of the other collections for use in the main Gallery for searching, filtering, sorting etc. This main Gallery filters an action area that shows the other collections depending on what needs to be seen.

 

In usage the independent Collections are edited and those edits are pushed to an Update Collection built from the same DataVerse Table. I am looking to write these collections back to DataVerse.

 

Dataverse TableWorking/Viewing CollectionUpdate Collection
ProjectscolProjectscolProjectsUpdate
TaskscolTaskscolTasksUpdate
PermitscolPermitscolPermitsUpdate
ClientscolClientscolClientsUpdate

 

I am able to update the Projects and write it back to Dataverse using the below method.

Code to update locally:

Patch(colProjects,ThisItem,
{
cr577_projectid: PcolProjectID.Text,
cr577_projectname: PcolProjectName.Text,
cr577_projectstatus: PcolProjectStatus.Selected.Value,
cr577_projectnotes: PcolProjectNotes.Text,
cr577_Assigned: PcolAssigned.Selected,
cr577_projectaddress: PcolProjectaddress.Text,
cr577_apn:PcolProjectAPN.Text,
cr577_JBAClient: PcolClient.Selected
}
);

Patch(colProjectsUpdates,ThisItem,
{
cr577_projectid: PcolProjectID.Text,
cr577_projectname: PcolProjectName.Text,
cr577_projectstatus: PcolProjectStatus.Selected.Value,
cr577_projectnotes: PcolProjectNotes.Text,
cr577_Assigned: PcolAssigned.Selected,
cr577_projectaddress: PcolProjectaddress.Text,
cr577_apn:PcolProjectAPN.Text,
cr577_JBAClient: PcolClient.Selected
}
);

 

Code to push it to Dataverse that works for the Project collection back to Dataverse.

ForAll(colProjectsUpdates,
Patch('JBA Projects',
LookUp('JBA Projects',cr577_projectid = colProjectsUpdates[@cr577_projectid]),
{
'Project Name': cr577_projectname,
'Project Status': cr577_projectstatus,
Assigned: cr577_Assigned,
'Project Address': cr577_projectaddress,
APN: cr577_apn,
'Project Notes': cr577_projectnotes,
'JBA Client': cr577_JBAClient
}
)
);

 

When I try using this same methodology on the other Tables in Dataverse it does not work. I can save locally, but I will not push back to Dataverse.

 

I am using the additional update collection to only show what is being updated to keep the final save call quick. I have used several ForAll, Patch, Collect, LookUp variations of the above code on the other tables to no avail. I thought it was an ID issue, but the collection have both their primary column and unique ID column included in the Collection build so I have hit a wall.

 

Any assistance would be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
ameeru18
Frequent Visitor

This is what ended up working after going 12 rounds with this issue. I do my editing and it saves into a Collection from a collection. When all the work is done I hit a final save button to push back to Dataverse. The Tasks side was the problematic side.

 

ForAll(
TasksColUpdates,
Patch(
'JBA Activity Lists',
First(
Filter('JBA Activity Lists', jba_jbataskid = jba_jbataskid)

),
{
jba_jbataskid:jba_jbataskid,
jba_ProjectID:jba_ProjectID,
jba_projecttask:jba_projecttask,
jba_taskpriority:jba_taskpriority,
jba_taskstatus:jba_taskstatus
}
)
);

//Clears the collection to make it ready to accept updates.
Clear(TasksColUpdates);

View solution in original post

4 REPLIES 4
RandyHayes
Super User
Super User

@ameeru18 

To start, your formula has the ForAll backward. You are trying to use it like a ForLoop in some development language - which PowerApps is not.  ForAll is a function that returns a table of records based on your iteration table and record schema.

It is more efficient to use the function as intended and will provide better performance as your Patch inside the ForAll including a LookUp at the same time will have horrible performance.

 

Your formula should be the following:

Patch('JBA Projects',
    ForAll(colProjectsUpdates,
    {
      cr577_projectid: cr577_projectid,
      'Project Name': cr577_projectname,
      'Project Status': cr577_projectstatus,
      Assigned: cr577_Assigned,
      'Project Address': cr577_projectaddress,
      APN: cr577_apn,
      'Project Notes': cr577_projectnotes,
      'JBA Client': cr577_JBAClient
      }
    )
);

Now in the above, I am assuming that cr577_projectid is the primary column.  If not, then replace as needed.

 

Perform the same style of formula for your other tables and pay special attention to any complex column types in your data.

 

IF you get an error stating that Patch is expected a Record, this is a misleading error...it really means that your record schema in the ForAll is not correct.  So, check all field names and make sure you are supplying the proper real name of the columns and that you are providing the exact type of data expected for the column.  Once you have that correct, the error message will go away and the formula will work properly.

 

Also note: if you happen to be getting this data in your collection from a Gallery, then there is no need even for the collection - all the data already exists in the gallery and can be retrieved from there, thus eliminating the need to duplicate your gallery data into another table in your app memory.

 

I hope this is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thank you for the response. Your method sets up without error, but when I run it I get the following error.


"Network error when using Patch function: Conflicts exist with changes on the server, please reload"

 

This is on my JBA Tasks DV table using the Taskscol and TaskscolUpdates collections.

 

Currently, I am working off of Collections and I use a Schema duplicate Update collection so that when I send the Patch - ForAll it only has the latest updates to comb through since I Clear the Update Collections every time I Push the final Patch or when I hit the Undo button.

 

When I run the Code below for this table it works rather quickly. However with my other Collections Tasks and Applications the same setup does not work.

 

ForAll(ProjectsColUpdates,     
Patch('JBA Projects',
LookUp('JBA Projects',cr577_projectid = ProjectsColUpdates[@cr577_projectid]),
{
'Project Name': cr577_projectname,
'Project Status': cr577_projectstatus,
Assigned: cr577_Assigned,
'Project Address': cr577_projectaddress,
APN: cr577_apn,
'Project Notes': cr577_projectnotes,
'JBA Client': cr577_JBAClient
}
)
);

Clear(ProjectsColUpdates); //Clears the collection to make it ready to accept updates.

 

I agree the ForAll is backward for PowerFx, but it was the only method that allowed the Update to the DV table without error. I reversed the two by accident after constantly getting the Network error.

 

This method is not working for my other Tables however and they are set up the exact same way. When I use your method with those tables I get the Network error when using Patch function: Conflicts exist with changes on the server, please reload. Is there a way to perform this reload am I overlooking something else? I have the main column in the run. Thanks

 

ameeru18
Frequent Visitor

This is what ended up working after going 12 rounds with this issue. I do my editing and it saves into a Collection from a collection. When all the work is done I hit a final save button to push back to Dataverse. The Tasks side was the problematic side.

 

ForAll(
TasksColUpdates,
Patch(
'JBA Activity Lists',
First(
Filter('JBA Activity Lists', jba_jbataskid = jba_jbataskid)

),
{
jba_jbataskid:jba_jbataskid,
jba_ProjectID:jba_ProjectID,
jba_projecttask:jba_projecttask,
jba_taskpriority:jba_taskpriority,
jba_taskstatus:jba_taskstatus
}
)
);

//Clears the collection to make it ready to accept updates.
Clear(TasksColUpdates);

hello @ameeru18 ,

 

I have tables in dataverse, I am looking these tables through a gallery in canavas app. I filter gallery and edit the records in gallery. The edited records are saved in collection. I have multiple records in collection. I am using either  unique identifier or primary columns to match and update records in dataverse.

 

1. APP-> Onstart :- ClearCollect(
updateTest,
ShowColumns(Table(Defaults(Test_BulkUpudate_GMB_Tables)),"zk_actiondate_test","zk_ch_priority_test","zk_project_id_test","zk_sourcetest", "zk_name", "zk_test_bulkupudate_gmb_tableid")
)

2. Gallery-> OnSelect:-

If(ThisItem.Test_BulkUpudate_GMB_Table in updateTest.zk_Test_BulkUpudate_GMB_TableId,
Update(updateTest,
LookUp(updateTest,zk_Test_BulkUpudate_GMB_TableId = ThisItem.Test_BulkUpudate_GMB_Table),
{
zk_Test_BulkUpudate_GMB_TableId: ThisItem.Test_BulkUpudate_GMB_Table,
zk_Project_ID_test: txt_projectID_1.Text,
zk_actiondate_test: ActionDate_1.SelectedDate,
zk_ch_priority_test: dp_Priority_1.Selected.Value,
zk_sourcetest: dp_sourceTest_1.Selected.Value,
zk_name:lb_name
}
),Collect(
updateTest,
{
zk_Test_BulkUpudate_GMB_TableId: ThisItem.Test_BulkUpudate_GMB_Table,
zk_Project_ID_test: txt_projectID_1.Text,
zk_actiondate_test: ActionDate_1.SelectedDate,
zk_ch_priority_test: dp_Priority_1.Selected.Value,
zk_sourcetest: dp_sourceTest_1.Selected.Value

}
))

 

3. Save button-> OnSelect:- I tried so many formulas.

I followed https://www.youtube.com/watch?v=8I0Pt_8I6k8&t=922s

a:- source - From video I followed. 

error- 

Krishna09_1-1677657047517.png

Krishna09_0-1677663581987.png

 

 

If(CountRows(updateTest)>0,
Patch(Test_BulkUpudate_GMB_Tables,updateTest)
;
Notify("Success",NotificationType.Success));

 

 

b:- source :- from your suggestion https://powerusers.microsoft.com/t5/Building-Power-Apps/Saving-an-Updated-Collection-back-to-Dataver...

error :- no change in records of dataverse.

ForAll(updateTest,Patch(Test_BulkUpudate_GMB_Tables,First(Filter(Test_BulkUpudate_GMB_Tables, Name =zk_name)),
{
Project_ID_test: zk_Project_ID_test,
ch_priority_test:zk_ch_priority_test


}));

b1:- error:-

Krishna09_0-1677656989045.png

 

ForAll(updateTest,Patch(Test_BulkUpudate_GMB_Tables,First(Filter(Test_BulkUpudate_GMB_Tables, Test_BulkUpudate_GMB_Table =zk_test_bulkupudate_gmb_tableid)),
{
Project_ID_test: zk_Project_ID_test,
ch_priority_test:zk_ch_priority_test


}));

c:- source- https://www.matthewdevaney.com/7-ways-to-use-the-patch-function-in-power-apps-cheat-sheet/#6.-Upsert...

error.-no change in records of dataverse. 

Patch(Test_BulkUpudate_GMB_Tables,
ShowColumns(updateTest,"zk_test_bulkupudate_gmb_tableid","zk_name")
);
Clear(updateTest)

 

d:- error

Krishna09_2-1677657122562.png

Formulae.-


Patch(Test_BulkUpudate_GMB_Tables,
LookUp(updateTest,
Name=zk_name,
{
Name:zk_name,
ch_priority_test:zk_ch_priority_test,
Project_ID_test:zk_project_id_test,
'Action Date_test':zk_actiondate_test,
sourceTest: zk_sourcetest}
));

e:- creating a new record in dataverse table.

UpdateIf(Test_BulkUpudate_GMB_Tables, Test_BulkUpudate_GMB_Table= zk_test_bulkupudate_gmb_tableid,
{ Test_BulkUpudate_GMB_Table:zk_test_bulkupudate_gmb_tableid,
ch_priority_test:zk_ch_priority_test,
Project_ID_test:zk_project_id_test,
sourceTest: zk_sourcetest

});

 

Please suggest and help me to solve, where I am going wrong here. I want to update collection with multiple records at same time to dataverse (upsert ) with either unique identifier or primary column.

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!      

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Community Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Top Solution Authors
Top Kudoed Authors
Users online (6,307)