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

@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

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (671)