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

Patch Function

Greetings,

How would I go about using a patch function to create and update a gallery selected item. As it is, my patch function only creates a new record and when trying to edit a gallery selected item, it creates a new record. 

*Sample Code*

 

SubmitBtn (OnSelect)
ForAll(CarCollection, Patch(Details, Defaults(Details), {Date:Date, FirstName:FirstName, LastName:LastName, License:License, Vehicle:Vehicle, InsuranceType:InsuranceType, InsuranceAmount:InsuranceAmount, GasMonthly:GasMonthly}));

1 ACCEPTED SOLUTION

Accepted Solutions

Hi@JRobinson12,

Do you want to use the gallery selected to update a certain item and create a new record when opening a new form?

I think you could generate an app directly based on the SP list, which brings you 3 screens, BrowseScreen for a gallery to display all the items, DetailScreen for a view form to display the detailed information, EditScreens for an edit form to create/update a record.

Automatically generated according to SPlist, this app has several default features that can achieve your needs.

1/ Edit a certain record when you select a record in the Gallery

Select an item within the Gallery and it will navigate you to a display form, you could click on the edit button to edit in an edit form.

step2.pngstep2-1.png

2/ Create a new record when opening a new form

Click the "+" button and it will navigate you to an edit form directly.

step3.png

step4.png

The above app generated based on the SP list needs you to create a new app. If you just want to make a few changes to the original app, you can try the following workaround.

Add 2 screens, Screen1 for a Gallery, Screen2 for the edit form.

Set the OnSelect property of the ">" button within the Gallery as below:

Select(Parent);EditForm(EditForm2);Navigate(Screen2, ScreenTransition.None)

Set the Items property of the Edit form as below:

Gallery2.Selected

Add a "+" button in Screen1 and set the OnSelect property as below:

NewForm(EditForm2);Navigate(Screen2, ScreenTransition.None)

Set the OnSelect property of the submit button as below:

SubmitForm(EditForm2);Navigate(Screen1)

Under this situation, you do not need a Patch() function bu a SubmitForm() function.

The SubmitForm() function could directly submit the edit/create result to the SP list.

110901GIF.gif

Hope it could help.

Best Regards,

Qi

 

View solution in original post

5 REPLIES 5
Super User
Super User

Hi @JRobinson12 

I understand that you would simply like to update the selected item in a gallery, not all at once, right?

If that's the case, you don't need a ForAll function. You can do this either inside or outside a gallery. Something like this should suffice:

 

 

Patch(
    Details,
    Gallery1.Selected,
{Date:Gallery1.Selected.Date, FirstName:Gallery1.Selected.FirstName, LastName:Gallery1.Selected.LastName, License:Gallery1.Selected.License, Vehicle:Gallery1.Selected.Vehicle, InsuranceType:Gallery1.Selected.InsuranceType, InsuranceAmount:Gallery1.Selected.InsuranceAmount, GasMonthly:Gallery1.Selected.GasMonthly}
)

 

 

If the patch-button is inside a gallery, you could replace Gallery1.Selected with ThisItem or simply remove it completely.

 

Let me know if it works.


Please click Accept as Solution if my post answered your question. Like my answer? Consider giving it a Thumbs Up. Others seeking the same answers will be happy you did.

Please click Accept as Solution if my post answered your question. Like my answer? Consider giving it a Thumbs Up. Others seeking the same answers will be happy you did.
Community Support
Community Support

Hi@JRobinson12,

Could you please tell me how you update your gallery selected item:

  1. use a control like TextInput or something else, a collection?
  2. what is your data source, an SP list, or something else?

Let me make it easy for you, you use the Defaults() parameter within the Patch() function, it will do create a new record rather than update an existing record.

If you have TextInput within your Gallery, you could try the following formula on the OnSelect property of the Button:

 

Patch(
          [@'Deatils'],
          LookUp([@'Deatils'], ID = ThisItem.ID),
          {
             ColumnName: TextInput1.Text
          }
)

 

On the other hand, combine that with your formula, do you want to write the collection to your gallery selected?

Note that if the collection and you 'Details' share the same column names, you should use the format like Collection[@ColumnName]

If so, please try to modify your formula as below

 

ForAll(
          CarCollection,
          Patch(
                    [@'Details'],
                    LookUp([@'Details'], ID = CarCollection[@'ID']),
                    {
                      Date: CarCollection[@Date],
                      FirstName: CarCollection[@FirstName],
                      LastName: CarCollection[@LastName],
                      ...
                    }
          )
)

 

Hope it could help.

Best Regards,

Qi

 

Thanks. How would I incorporate this function with "Defaults" function to create a new item. I want when a item is selected from the gallery and changes are made, it updates that record instead of creating a new one and when a new form is created, it creates a new record in the data source

My data source is a sharepoint list

Hi@JRobinson12,

Do you want to use the gallery selected to update a certain item and create a new record when opening a new form?

I think you could generate an app directly based on the SP list, which brings you 3 screens, BrowseScreen for a gallery to display all the items, DetailScreen for a view form to display the detailed information, EditScreens for an edit form to create/update a record.

Automatically generated according to SPlist, this app has several default features that can achieve your needs.

1/ Edit a certain record when you select a record in the Gallery

Select an item within the Gallery and it will navigate you to a display form, you could click on the edit button to edit in an edit form.

step2.pngstep2-1.png

2/ Create a new record when opening a new form

Click the "+" button and it will navigate you to an edit form directly.

step3.png

step4.png

The above app generated based on the SP list needs you to create a new app. If you just want to make a few changes to the original app, you can try the following workaround.

Add 2 screens, Screen1 for a Gallery, Screen2 for the edit form.

Set the OnSelect property of the ">" button within the Gallery as below:

Select(Parent);EditForm(EditForm2);Navigate(Screen2, ScreenTransition.None)

Set the Items property of the Edit form as below:

Gallery2.Selected

Add a "+" button in Screen1 and set the OnSelect property as below:

NewForm(EditForm2);Navigate(Screen2, ScreenTransition.None)

Set the OnSelect property of the submit button as below:

SubmitForm(EditForm2);Navigate(Screen1)

Under this situation, you do not need a Patch() function bu a SubmitForm() function.

The SubmitForm() function could directly submit the edit/create result to the SP list.

110901GIF.gif

Hope it could help.

Best Regards,

Qi

 

View solution in original post

Helpful resources

Announcements
secondImage

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

Top Solution Authors
Top Kudoed Authors
Users online (18,043)