cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

Patch to add or edit record in SP List

Hi,

 

I'm trying to figure out how I can add or edit a record using patch. I am currently  using one form to add or edit, however upon checking while using the patch function it doesn't do both it only edit the data. Hoping someone can help me out on what formula should I use to add/edit a record using patch.

 

Thanks in advance 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Patch to add or edit record in SP List

Hi @Anonymous,

How do you submit your form data into your SP list using Patch function? Could you please share a bit more about the formula?
I have made a test on my side, please take a try with the following workaround:

7.JPG

Set the OnSelect property of the "Submit" button to following formula:

If(
    EditForm1.Mode=FormMode.New,
    Patch('20181026_case11',Defaults('20181026_case11'),EditForm1.Updates),  /* <-- '20181026_case11' represents the SP list data source in my app*/
    Patch('20181026_case11',BrowseGallery1.Selected,EditForm1.Updates)
)

Note: The EditForm1 represents the Edit form within my app. And within the first screen of my app, I use a Gallery control (called BrowseGallery1) to list all records of my SP list datasource.

On your side, you should type the following formula:

If(
    EditForm1.Mode=FormMode.New,   /* <-- EditForm1 represents the Edit form control within your app */
    Patch(                         /* <-- Add a new record */
'YourSPList',
Defaults('YourSPList'),
EditForm1.Updates
), Patch( /* <-- Modify an existing record */
'YourSPList',
'Type Item property formula of your Edit form', /* If you don't use a Gallery to list all your SP list records, you should type the Item property formula of the Edit form*/
EditForm1.Updates
) )

Or

If(
    EditForm1.Mode=FormMode.New,   /* <-- EditForm1 represents the Edit form control within your app */
    Patch(                         /* <-- Add a new record */
'YourSPList',
Defaults('YourSPList'),
{
Column1: DataCardValue1.Text,
Column2: DataCardValue2.Text,
...
}
), Patch( /* <-- Modify an existing record */
'YourSPList',
'Type Item property formula of your Edit form', /* If you don't use a Gallery to list all your SP list records, you should type the Item property formula of the Edit form*/
{
Column1: DataCardValue1.Text,
Column2: DataCardValue2.Text,
...
}
) )

Note: 'The Item property formula of your Edit form' represents the existing record you want to modify within your Edit form. You could also find the corresponding record you want to modify using LookUp function based some conditions.

More details about the Patch function, please check the following article:

Patch function

When you use the Patch function to modify an existing record, you must find the record firstly, then put it on the second parameter value of the Patch function (as mentioned above).

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Highlighted
Advocate II
Advocate II

Re: Patch to add or edit record in SP List

if you are using a form, you can use the function "NewForm" for add a new record and then EditForm to edit that record. 

Highlighted
Community Support
Community Support

Re: Patch to add or edit record in SP List

Hi @Anonymous,

How do you submit your form data into your SP list using Patch function? Could you please share a bit more about the formula?
I have made a test on my side, please take a try with the following workaround:

7.JPG

Set the OnSelect property of the "Submit" button to following formula:

If(
    EditForm1.Mode=FormMode.New,
    Patch('20181026_case11',Defaults('20181026_case11'),EditForm1.Updates),  /* <-- '20181026_case11' represents the SP list data source in my app*/
    Patch('20181026_case11',BrowseGallery1.Selected,EditForm1.Updates)
)

Note: The EditForm1 represents the Edit form within my app. And within the first screen of my app, I use a Gallery control (called BrowseGallery1) to list all records of my SP list datasource.

On your side, you should type the following formula:

If(
    EditForm1.Mode=FormMode.New,   /* <-- EditForm1 represents the Edit form control within your app */
    Patch(                         /* <-- Add a new record */
'YourSPList',
Defaults('YourSPList'),
EditForm1.Updates
), Patch( /* <-- Modify an existing record */
'YourSPList',
'Type Item property formula of your Edit form', /* If you don't use a Gallery to list all your SP list records, you should type the Item property formula of the Edit form*/
EditForm1.Updates
) )

Or

If(
    EditForm1.Mode=FormMode.New,   /* <-- EditForm1 represents the Edit form control within your app */
    Patch(                         /* <-- Add a new record */
'YourSPList',
Defaults('YourSPList'),
{
Column1: DataCardValue1.Text,
Column2: DataCardValue2.Text,
...
}
), Patch( /* <-- Modify an existing record */
'YourSPList',
'Type Item property formula of your Edit form', /* If you don't use a Gallery to list all your SP list records, you should type the Item property formula of the Edit form*/
{
Column1: DataCardValue1.Text,
Column2: DataCardValue2.Text,
...
}
) )

Note: 'The Item property formula of your Edit form' represents the existing record you want to modify within your Edit form. You could also find the corresponding record you want to modify using LookUp function based some conditions.

More details about the Patch function, please check the following article:

Patch function

When you use the Patch function to modify an existing record, you must find the record firstly, then put it on the second parameter value of the Patch function (as mentioned above).

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,574)