cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kevingeorget
Resolver I
Resolver I

Patch function to update existing record

Hi PowerApp users,

I'm trying to edit couple of fields of an item from an edit screen.

Attached screenshot of simple form.

I'm using the Gallery control to filter the same item and to update 3 fields associated with the item.

I use the Patch function as below, on the onselect action of the Save button

 

UpdateContext({EditRecord:0});
Patch('MarksSheet',First(Filter('MarksSheet',Title=ThisItem.Title)),{Chemistry_x0020_Marks:ChemTxt, Physics_x0020_Marks:PhyTxt,Math_x0020_Marks:MathTxt})

 

Anyhelp appreciated.

Regards,

Kevin

 

1 ACCEPTED SOLUTION

Accepted Solutions
kevingeorget
Resolver I
Resolver I

After 2 hours of breaking my head, found the solution- i had to add ther term 'value' to each expression

UpdateContext({EditRecord:0});
Patch('EditableGrid MarksSheet',{ID: Value(DataCardValue6.Text)},{Chemistry_x0020_Marks:Value(ChemTxt.Text),Physics_x0020_Marks:Value(PhyTxt.Text),Math_x0020_Marks:Value(MathTxt.Text)})

 

View solution in original post

13 REPLIES 13
kevingeorget
Resolver I
Resolver I

After 2 hours of breaking my head, found the solution- i had to add ther term 'value' to each expression

UpdateContext({EditRecord:0});
Patch('EditableGrid MarksSheet',{ID: Value(DataCardValue6.Text)},{Chemistry_x0020_Marks:Value(ChemTxt.Text),Physics_x0020_Marks:Value(PhyTxt.Text),Math_x0020_Marks:Value(MathTxt.Text)})

 

View solution in original post

Hello Mr @kevingeorget ,

 

I am having a problem, I am using this code on my Submit Button

If(DataCardValue1.Selected.Value = "Time Off",
Patch(
   LeaveRequests,
   Defaults(LeaveRequests),
   {
   User:     DataCardValue6.Text,
   UserEmail:
   {
 Claims: Concatenate(
          "i:0#.f|membership|",
          DataCardValue3.Selected.Email // Person email
          ),
          Department: "",
          DisplayName: "",
          Email: User().Email, // Person email
          JobTitle: "",
          Picture: ""

   },

   Description: DataCardValue2.Text,
   TimeOffDate: DataCardValue22.SelectedDate,
   TimeOffFrom: DataCardValue19.Selected,
   TimeOffTo: DataCardValue20.Selected,
   TotalTimeRequested: Label23.Text
   
    }
  )
); Navigate(SucessScreen,None)

and when I open a record in edit mode, its creating a new entry in sharepoint, how do I fix this? issue?

Hi @MH3 ,

Apologies for the late reply. In case you haven't got the solution and from what i could understand, please find the explanation below.

1. May be you can use a context variable when navigating to the screen (where the patch and submit button is present) and set its value as either New or Edit. Like this,

Navigate(ScrnLeaveRequest,ScreenTransition.None,{varFormMode:"New"}).

2. Update the OnSelect event of the button checking whether it's "Time Off" and whether the form mode is new or edit.

If(And(DataCardValue1.Selected.Value = "Time Off",varFormMode="New"),
Patch(
   LeaveRequests,
   Defaults(LeaveRequests),
   {
   User:     DataCardValue6.Text,
   UserEmail:
   {
 Claims: Concatenate(
          "i:0#.f|membership|",
          DataCardValue3.Selected.Email // Person email
          ),
          Department: "",
          DisplayName: "",
          Email: User().Email, // Person email
          JobTitle: "",
          Picture: ""

},

Description: DataCardValue2.Text,
   TimeOffDate: DataCardValue22.SelectedDate,
   TimeOffFrom: DataCardValue19.Selected,
   TimeOffTo: DataCardValue20.Selected,
   TotalTimeRequested: Label23.Text
  
    }
  )
); Navigate(SucessScreen,None,

Patch(
   LeaveRequests,
 Lookup(LeaveRequests,ID="THE ID You want to update"),
   {
   User:     DataCardValue6.Text,
   UserEmail:
   {
 Claims: Concatenate(
          "i:0#.f|membership|",
          DataCardValue3.Selected.Email // Person email
          ),
          Department: "",
          DisplayName: "",
          Email: User().Email, // Person email
          JobTitle: "",
          Picture: ""

},

Description: DataCardValue2.Text,
   TimeOffDate: DataCardValue22.SelectedDate,
   TimeOffFrom: DataCardValue19.Selected,
   TimeOffTo: DataCardValue20.Selected,
   TotalTimeRequested: Label23.Text
  
    }
  )
); Navigate(SucessScreen,None

)

Please give this a try and let me know how it goes.

Cheers,

Kevin

Hi @kevingeorget ,

 

well thanks for your reply.

 

I did this

If(DataCardValue1.Selected.Value = "Time Off",
Patch(
   LeaveRequests,
   {ID:LeaveRequests.Selected.ID},
   {
   LeaveID: CurrentUserID,    
   User:     DataCardValue6.Text,
   UserEmail:
   {
 Claims: Concatenate(
          "i:0#.f|membership|",
          DataCardValue3.Selected.Email // Person email
          ),
          Department: "",
          DisplayName: "",
          Email: User().Email, // Person email
          JobTitle: "",
          Picture: ""

   },

   Description: DataCardValue2.Text,
   TimeOffDate: DataCardValue22.SelectedDate,
   TimeOffFrom: DataCardValue19.Selected,
   TimeOffTo: DataCardValue20.Selected,
   TotalTimeRequested: Label23.Text
   
    }
  )
); Navigate(SucessScreen,None)

I replaced the defaults parameter with the Gallery.selected item to edit that record. is this code right?

For updating a record, this piece of code looks good to me.

Hi @kevingeorget ,

 

Actually,

1) it's not for updating only, when I submit a record, this code will be the same and when I edit a record from the gallery it also works good.

 

2) But when I go for create new record, the form shows the previous patched data in the form fields, why is that happening like that? any idea

3) I display form fields when I select a Leave type in the Form from the DropDown Control.

2) But when I go for create new record, the form shows the previous patched data in the form fields, why is that happening like that? any idea

Is the gallery and the form in the same screen or you're navigating to the form screen on select from a gallery item?

You could either reset each control when showing/displaying the form control (Reset control) or when the submit is done you could reset the control then.

..; Navigate(SucessScreen,None);Reset(Dropdown1)

 

 

Hi @kevingeorget 

Let me show you the Process of Navigation through Pictures

1)When User Navigates here from main screen, hit (+) to create new record1 Create Button1 Create Button

2)When User Navigates here from (+),

2 From, without Selection2 From, without Selection
3)When User Navigates here from (+), and then he will select a Leave Type

3, form, selected leave type3, form, selected leave type

4) 3)When User Navigates here from (+), and then he will select a Leave Type, and then he fills out the data and then submits.
after submitting, I am navigating back to the Gallery Screen.
4 form , Submit Button Code4 form , Submit Button Code

I assume you're using Patch since you don't intend to update the entire fields in the Form or database. If you're updating all the fields, why not use SubmitForm(NewForm)?

Is 

 {ID:LeaveRequests.Selected.ID},

in your Patch working even for creating new records? 

It is strange that you're still getting the old record when using NewForm(NewForm) along with Navigate.

Nice screens btw 🙂

Cheers,

Kevin

 

 

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!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,185)