cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ez1138
Helper V
Helper V

PowerApp - Saving causes table data connected to App to disappear

Hi,

 

I have a few tables that seem to mess with each other and I can't figure out why.  What happens is when I save the detail within the App, the company and/or the contacts that are connected to audit sometimes are no longer connected to the audit.  I can see this when I listed all my audits in a gallery and the company field is now blank and I have to re-add it in the audit.  When happens then, sometimes, is that the contacts for that company also are removed.  The code I use to "save" any changes is on the bottom.  If 

 

Here are my main tables and how the PowerApp works.

 

- Audit

- Company (each company has multiple contacts from the contacts table) 

- Contacts (contacts can be created/edited from App)

 

 

If( // Check if you are adding or editing record
EditForm_Audits_Company.Mode = FormMode.New,
Patch(
'[dbo].[audit]',
Defaults('[dbo].[audit]'),
EditForm_Audits_Company.Updates
);Navigate(BrowseGallery_Audits),
Patch(
'[dbo].[audit]',
BrowseGallery_Audits.Selected,
EditForm_Audits_Company.Updates
);Navigate(Screen_Detail_Audits_Company)
1 ACCEPTED SOLUTION

Accepted Solutions

Hi @ez1138 ,

Try this

If(
   EditForm_Audits_Company.Mode = FormMode.New,
   Patch(
      '[dbo].[audit]',
      Defaults('[dbo].[audit]'),
      EditForm_Audits_Company.Updates
   );
Navigate(BrowseGallery_Audits),
Patch(
   '[dbo].[audit]',
   {auditID:BrowseGallery_Audits.Selected.auditID},
   EditForm_Audits_Company.Updates
);
Navigate(Screen_Detail_Audits_Company)

 

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.

Visit my blog Practical Power Apps

View solution in original post

6 REPLIES 6
WarrenBelz
Super User
Super User

Hi @ez1138 ,

What exactly are you doing with the second Patch on the same list using the same data? The first is a new record, but you are then updating with the same data.

 

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.

Visit my blog Practical Power Apps

Hi Warren, thanks for the reply. 

 

I'm not an expert, obviously.  I just pulled this code from a past "back when", and it seemed to work.  Are you saying I should just dump the last portion of the code?  I struck it out.

 

If// Check if you are adding or editing record
EditForm_Audits_Company.Mode = FormMode.New,
Patch(
'[dbo].[audit]',
Defaults('[dbo].[audit]'),
EditForm_Audits_Company.Updates
);Navigate(BrowseGallery_Audits),
Patch(
'[dbo].[audit]',
BrowseGallery_Audits.Selected,
EditForm_Audits_Company.Updates
);Navigate(Screen_Detail_Audits_Company)

Hi @ez1138 ,

Actually forget that - I missed the top bit - must have read too quickly. Do you have a unique identifier in your record, if so, what is its name and type.

Yes.  Here they are.

 

For my audit table, it's audit_ID, company is company_ID and contacts is contacts_ID.

Hi @ez1138 ,

Try this

If(
   EditForm_Audits_Company.Mode = FormMode.New,
   Patch(
      '[dbo].[audit]',
      Defaults('[dbo].[audit]'),
      EditForm_Audits_Company.Updates
   );
Navigate(BrowseGallery_Audits),
Patch(
   '[dbo].[audit]',
   {auditID:BrowseGallery_Audits.Selected.auditID},
   EditForm_Audits_Company.Updates
);
Navigate(Screen_Detail_Audits_Company)

 

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.

Visit my blog Practical Power Apps

WarrenBelz
Super User
Super User

Hi @ez1138 ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

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.

Visit my blog Practical Power Apps

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (3,990)