cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

How to patch a new record (defaults) to CDS and update existing record (edit form) from a single control

Hi,

 

I have 2 entities, Orders and Groups. Orders are one-to-many Groups.

 

I have 2 galleries, 1 gallery displaying Orders, another gallery showing Groups from the selected Order in the previous gallery.

 

I have a submit button where if a user would like to add a new Group to the Order, they are brought to a screen with a standard form. When they're done entering info, the submit button is a Patch that connects the datacard values for the Group to the selected Order. At this point, I wasn't totally sure how to make a SubmitForm patch to the related entity (Orders) but this worked for the time being.

 

However, I have it so far that when an edit Group button is used, the selected Group is going through the regular EditForm() process. Thus when a user presses the submit button it is patching the defaults above instead of simply editing the selected record, creating a new record - not ideal.

Below is the button used on the screen whether they make a new Group record or edit the Group record. It's worth noting on the previous screen are 2 buttons: Add new Group (NewForm), Edit Group (EditForm).

 

 

 

 

Patch(
  [@Groups],
  Defaults([@Groups]),
    {
      'OrderRelationship': galleryOrders.Selected
      'Group Name': DataCardValue.Text
    }
);
Refresh([@Groups]);
ResetForm(frmEditGroup);
Navigate('Order Detail Screen')

 

 

 

 

Question: What is the best solution to keep a single screen and single control that could take care of both patching a new record as well as updating a selected record?


Edit: This is solved.

Added:

If(frmEditGroup.Mode=FormMode.New, Patch(), SubmitForm(frmEditGroup)

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: How to patch a new record (defaults) to CDS and update existing record (edit form) from a single control

Hi @virakones ,

Have you solved your problem?

Do you want to add or edit records using a single one button?

 

Based on the solution that you mentioned, I agree with you almost. You could use the frmEditGroup.Mode=FormMode.New condition to determine if you are adding a record or editing a record in your canvas app.

 

Actually, the Patch function could also achieve your needs. Please take a try with the following formula:

If(
   frmEditGroup.Mode = FormMode.New, 
   Patch(
         [@Groups],
         Defaults([@Groups]),
         {
           'OrderRelationship': galleryOrders.Selected
           'Group Name': DataCardValue.Text
         }
   ), 
   Patch(
         [@Groups],
         galleryGroups.Selected,  // or Type LookUp([@Groups], 'Unique Identifier Column' = galleryGroups.Selected.'Unique Identifier Column')
         frmEditGroup.Updates
   )
);
Refresh([@Groups]);
ResetForm(frmEditGroup);
Navigate('Order Detail Screen')

 

If you have solved your problem, please consider go ahead to click "Accept as Solution" to identify this thread has been solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Highlighted
Community Support
Community Support

Re: How to patch a new record (defaults) to CDS and update existing record (edit form) from a single control

Hi @virakones ,

Have you solved your problem?

Do you want to add or edit records using a single one button?

 

Based on the solution that you mentioned, I agree with you almost. You could use the frmEditGroup.Mode=FormMode.New condition to determine if you are adding a record or editing a record in your canvas app.

 

Actually, the Patch function could also achieve your needs. Please take a try with the following formula:

If(
   frmEditGroup.Mode = FormMode.New, 
   Patch(
         [@Groups],
         Defaults([@Groups]),
         {
           'OrderRelationship': galleryOrders.Selected
           'Group Name': DataCardValue.Text
         }
   ), 
   Patch(
         [@Groups],
         galleryGroups.Selected,  // or Type LookUp([@Groups], 'Unique Identifier Column' = galleryGroups.Selected.'Unique Identifier Column')
         frmEditGroup.Updates
   )
);
Refresh([@Groups]);
ResetForm(frmEditGroup);
Navigate('Order Detail Screen')

 

If you have solved your problem, please consider go ahead to click "Accept as Solution" to identify this thread has been solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Helper I
Helper I

Re: How to patch a new record (defaults) to CDS and update existing record (edit form) from a single control

@v-xida-msft 

Thank you for the help! Your suggestion for form.Updates  is new to me, I might have to research this a bit more.

 

Thank you again.

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,782)