cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nliu
Helper II
Helper II

How to modify a record with Patch ?

Hi,

 

I have an app which is connected with multiple datasource (SP List x6). I'm using the patch function to record in once the data in all my SP List it works great but when I want to modify a record with a new data (it could by any of my columns in SP List) it always create a new record... It is not update/modify.

 

How can I do to fix this ? 

 

I have got this formula on my button "Submit form" :

 

SubmitForm(FormIdentification);;

Patch('ESU - DT'; Defaults'ESU-DT'; { Title: Dropdown4.SelectedText.Value; Département: Dropdown5.SelectedText.Value; 'Ville/Commune': DataCardValue23.Text; P_x00e9_riode_x0020_de_x0020_r_x: DatePicker2.SelectedDate; 'PR x à x': DataCardValue24.Text; 'Coordonées GPS': DataCardValue25.Text; 'Surface totale du chantier (m²)': DataCardValue22.Text })

...x6

 

Thank you for your help 🙂 

1 ACCEPTED SOLUTION

Accepted Solutions
yashag2255
Dual Super User II
Dual Super User II

Hey @nliu 

 

Yep! That is why an if condition is required. 

 

Glad that it is resolved. If this issue is resolved, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

12 REPLIES 12
yashag2255
Dual Super User II
Dual Super User II

Hi @nliu 

 

this is because Defaults() creates a new row in the datasource, if you are looking to update an existing record, you need to update the formula as:

SubmitForm(FormIdentification);;

Patch('ESU - DT'; LookUp('ESU - DT';Col1 = "Value1"); { Title: Dropdown4.SelectedText.Value; Département: Dropdown5.SelectedText.Value; 'Ville/Commune': DataCardValue23.Text; P_x00e9_riode_x0020_de_x0020_r_x: DatePicker2.SelectedDate; 'PR x à x': DataCardValue24.Text; 'Coordonées GPS': DataCardValue25.Text; 'Surface totale du chantier (m²)': DataCardValue22.Text })

 
Here, the updated part need to be modified to uniquely identify the row for update operation. Col1 needs to be replaced with the name of column and Value1 with the control/value for Col1.
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

@yashag2255 

Thank you for your response, it's updating the data but now it doesn't create a new record. I would like to create and modify is it possible ?

yashag2255
Dual Super User II
Dual Super User II

Hey @nliu 

 

In which condition do you want to create a new record? (or update an existing one?) If you can share more details, we can modify that formula accordingly. 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

@yashag2255 

 

Ok, I work in public works and I want a database which contains my worksites.

So I want to create a new record for each new worksite but usually a worksite last at least few days so I want to update day by day my record with new informations.

 

 

yashag2255
Dual Super User II
Dual Super User II

Hi @nliu 

 

For that you can use an if condition to create/update data based on worksites name.
 
Assumed Schema
SPList Name -> MySPList
Column to store Worksite Name -> WorksiteName
 
Formula ->
SubmitForm(FormIdentification);;
If(DataCardsValue1.Text in MySPList.WorksiteName,Patch('ESU - DT'; LookUp('ESU - DT';Col1 = "Value1"); { Title: Dropdown4.SelectedText.Value; Département: Dropdown5.SelectedText.Value; 'Ville/Commune': DataCardValue23.Text; P_x00e9_riode_x0020_de_x0020_r_x: DatePicker2.SelectedDate; 'PR x à x': DataCardValue24.Text; 'Coordonées GPS': DataCardValue25.Text; 'Surface totale du chantier (m²)': DataCardValue22.Text }),Patch('ESU - DT'; Defaults('ESU - DT'); { Title: Dropdown4.SelectedText.Value; Département: Dropdown5.SelectedText.Value; 'Ville/Commune': DataCardValue23.Text; P_x00e9_riode_x0020_de_x0020_r_x: DatePicker2.SelectedDate; 'PR x à x': DataCardValue24.Text; 'Coordonées GPS': DataCardValue25.Text; 'Surface totale du chantier (m²)': DataCardValue22.Text }))
 
 
In a case, this depends on Form Mode,
 
If(Form1.Mode = FormMode.New,Patch('ESU - DT'; Defaults('ESU - DT'); { Title: Dropdown4.SelectedText.Value; Département: Dropdown5.SelectedText.Value; 'Ville/Commune': DataCardValue23.Text; P_x00e9_riode_x0020_de_x0020_r_x: DatePicker2.SelectedDate; 'PR x à x': DataCardValue24.Text; 'Coordonées GPS': DataCardValue25.Text; 'Surface totale du chantier (m²)': DataCardValue22.Text }),Patch('ESU - DT'; LookUp('ESU - DT';Col1 = "Value1"); { Title: Dropdown4.SelectedText.Value; Département: Dropdown5.SelectedText.Value; 'Ville/Commune': DataCardValue23.Text; P_x00e9_riode_x0020_de_x0020_r_x: DatePicker2.SelectedDate; 'PR x à x': DataCardValue24.Text; 'Coordonées GPS': DataCardValue25.Text; 'Surface totale du chantier (m²)': DataCardValue22.Text }))
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

@yashag2255 

 

The problem is a worksite is defined by 3 parameters : Product, Where and When... Maybe I can use a Filter instead of LookUp to find the right record ? Or can I connect the Item selected in my Gallery (which is connected with 'ESU-DTECA') with the datasource 'ESU-DT' ?

 

Thank you for helping me

yashag2255
Dual Super User II
Dual Super User II

Hey @nliu 

 

Filter returns all the records satisfying this criteria, whereas lookup gets only the required record (the first record that satisfies all the criteria). That is why we use LookUp in a patch formula.
 
If you have a gallery, then please update the expression as:
 
 
SubmitForm(FormIdentification);;
If(galleryName.Selected.ID in 'ESU - DT'.ID,Patch('ESU - DT'; LookUp('ESU - DT';ID= galleryName.Selected.ID); { Title: Dropdown4.SelectedText.Value; Département: Dropdown5.SelectedText.Value; 'Ville/Commune': DataCardValue23.Text; P_x00e9_riode_x0020_de_x0020_r_x: DatePicker2.SelectedDate; 'PR x à x': DataCardValue24.Text; 'Coordonées GPS': DataCardValue25.Text; 'Surface totale du chantier (m²)': DataCardValue22.Text }),Patch('ESU - DT'; Defaults('ESU - DT'); { Title: Dropdown4.SelectedText.Value; Département: Dropdown5.SelectedText.Value; 'Ville/Commune': DataCardValue23.Text; P_x00e9_riode_x0020_de_x0020_r_x: DatePicker2.SelectedDate; 'PR x à x': DataCardValue24.Text; 'Coordonées GPS': DataCardValue25.Text; 'Surface totale du chantier (m²)': DataCardValue22.Text }))
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

@yashag2255 

I tried what you wrote and tried to do some arrangement but it still doesn't work... 😞 

@yashag2255 

 

Ok I tried something else but still some problems, please find some photo of my app & datasourcesTargetScreens.jpgFormIdentification.jpgAs you can see in DataSource1 it doesn't take the modification and it creates a new record. But it works perfectly in my datasource2ESU-DTECA.jpgESU-DT.jpg

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,251)