cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
trishmalloy
Post Partisan
Post Partisan

When a record is edited a new one is created, the existing record isn't updated

Hello again,

 

What should I check to see why this is happening?

 

Trish

21 REPLIES 21
SkiDK
Solution Sage
Solution Sage

If you use a form: you have to submit on an 'EditForm'

If you use patch, you need to:

Patch(
  DataSource,
  LookUp(DataSource, Id = ThisItemId),
  {
    ...
  }
)

You have to specify the item to edit. If you use the next, you will create a new item:

Patch(
  DataSource,
  Defaults(DataSource),
  {
    ...
  }
)
v-siky-msft
Community Support
Community Support

Hi  @trishmalloy ,

 

Can you share the formulas you use?

If you are using Patch function, you should to check the BaseRecord part in your expression. BaseRecord means the record you want to modify. You can use First(Datasource) or GalleryName.Selected in Base Record part to specify a record, also you can use LookUp() function to look up one based on the condition.  If we use Defaults(DataSource) in Base Record part, it will create a new record.

Snipaste_2019-11-14_12-46-01.png

For more reference, please check this article: Patch function in PowerApps 

If you are not using Patch function , please post back your formulas and screenshots, it is useful to help you.

Best regards,

Sik

If my post is helpful for you, please click on “Accept as Solution” to help other members find it more quickly.

 

This is the Save formula on the Edit form:

 

SubmitForm('New workout');Patch('Client Workout',Last('Client Workout'),{Client_x0020_Name:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Id:Gallery2.Selected.ID, Value:Gallery2.Selected.'Client Name'}});ResetForm('New workout');Navigate('Client Profile and List of Workouts', ScreenTransition.None)

 

This is the Save formula on the New form:

 

SubmitForm('New workout');Patch('Client Workout',Last('Client Workout'),{Client_x0020_Name:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Id:Gallery2.Selected.ID, Value:Gallery2.Selected.'Client Name'}});ResetForm('New workout');Navigate('Client Profile and List of Workouts', ScreenTransition.None)

 

Note:  The client name is a read only form on both the new and edit screens.  I have to be able to add the name to the new or edited form.

Hi @trishmalloy ,

 

Do you mean when you submit the Form in edit mode, a new record will be created?

An alternatively workaround:

Use patch function to edit or new the record, If the form mode is new, it will create a new record, if the form mode is eidt, it will edit the first record.(you can replace 'First('Client Workout')' to any other record you want to edit.). 'New workout'.Updates' will patch all form's entered value and also patch the client name at the same time.

 

Patch('Client Workout',
If('New workout'.Mode= FormMode.New ,Defaults('Client Workout'),'New workout'.Mode= FormMode.Edit, First('Client Workout')),
'New workout'.Updates ,
{Client_x0020_Name:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Id:Gallery2.Selected.ID, Value:Gallery2.Selected.'Client Name'}});ResetForm('New workout');Navigate('Client Profile and List of Workouts', ScreenTransition.None)

 

Please have a try, If this doesn't work, please post back the screenshots and formulas of error.

Best regards,

Sik

If my post is helpful for you, please click on “Accept as Solution” to help other members find it more quickly.

Is your Form in EditMode for Edit and NewMode for New? Seems your form maybe in NewMode for Edit which would create a new item

Hi @Eelman ,

 

 

Please check this formula:  

If('New workout'.Mode= FormMode.New ,Defaults('Client Workout'),'New workout'.Mode= FormMode.Edit, First('Client Workout'))

If the form is in new mode, it will create a new record because of Defaults() function. If the form is in Eidt mode, It will patch record to the first record, in another word, it will edit and modify the first record.

Best regards,

Sik

@v-siky-msft sorry, my question was directed to @trishmalloy ... I should've used the '@' to indicate this, my bad.

 

You are correct, your code does exactly what you explained. My question to @trishmalloy is that it appears to me that SubmitForm() is submitting a new form (ie creating a new record and not updating the existing record) for Edit Form because it isn't in Edit Mode. My 'guess' is that it is in 'NEW' Mode. If that makes sense?

Hello @v-siky-msft , 

 

I'm still running into the issue of another record being created.  Here is some more detail.

 

Create new workout screen

1. Create new record, form is in New mode.  Here is the formula for the save button:

 

SubmitForm('New workout');Patch('Client Workout',Last('Client Workout'),{Client_x0020_Name:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Id:Gallery2.Selected.ID, Value:Gallery2.Selected.'Client Name'}});ResetForm('New workout');Navigate('Client Profile and List of Workouts', ScreenTransition.None)

 

View workout screen

 

2. Edit record that was just created, form is in Edit mode. Here is the formula for the save button:

Patch('Client Workout', If('New workout'.Mode= FormMode.New ,Defaults('Client Workout'),'Edit workout'.Mode= FormMode.Edit, First('Client Workout')), 'Edit workout'.Updates , {Client_x0020_Name:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Id:Gallery2.Selected.ID, Value:Gallery2.Selected.'Client Name'}});ResetForm('New workout');Navigate('Client Profile and List of Workouts', ScreenTransition.None)

 

Hi @trishmalloy ,

 

Could you please share more with your scenario?

The patch function in your NO.2 I have been test on my side, and it can work well.

If you can share more information about your app and issue, it would be better to help you.

Best regards,

Sik

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (20,238)