cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
trishmalloy
Level: Powered On

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
Level 8

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

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
Level 10

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

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.

 

trishmalloy
Level: Powered On

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

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.

v-siky-msft
Level 10

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

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.

Eelman
Level 8

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

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

v-siky-msft
Level 10

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

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

Eelman
Level 8

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

@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?

trishmalloy
Level: Powered On

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

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)

 

v-siky-msft
Level 10

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

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
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,025)