cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

PATCH creates empty record on SP list with required fields

What I want:

Create record on SP list using Patch() and get back errors using Errors().

It should be possible according to documentation. But it isn't.

 

Patch() creates record even if required fields are empty and what's more it's not possible to test the created record against Errors() function. SubmitForm() works as intended.

 

What's the problem:

  1. Patch() function creates record on SP list even if the field that is required is empty. SubmitForm() works fine and displays errors.
  2. Can't test record returned from Patch() against Errors() function. I get error message: "The type of the record is incompatible with source.".

Steps to recreate:

  1. Create custom SP list, don't add any columns. "Title" column is required by default.
  2. Add button control to your PowerApps Canvas app.
  3. Set OnSelect property to:

 

 

// Create record on SP list even if "Title" field is empty.
// Also, save it as a variable to test against Errors() function.
ClearCollect(NewRecord, Patch(custom_sp_list, Defaults(custom_sp_list), {Title: ""}));

// Error: "...record is incompatible type...".
ClearCollect(Errors, Errors(custom_sp_list, First(NewRecord)));

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Helper I
Helper I

Hi @sch 

I have tested this and got it to work as follows:

The button has this code:

// Create record on SP list even if "Title" field is empty.
// Also, save it as a variable to test against Errors() function.
UpdateContext({NewRecord: Patch(CSVCreationList, Defaults(CSVCreationList))});

// Error: "...record is incompatible type...".
ClearCollect(Errors, Errors(CSVCreationList))

and this is how the Errors collection looks:

Screen Shot 2019-11-26 at 8.51.10 AM.png

 

When you give Title the value of "" SharePoint does not consider that to be Blank.

View solution in original post

2 REPLIES 2
Highlighted
Helper I
Helper I

Hi @sch 

I have tested this and got it to work as follows:

The button has this code:

// Create record on SP list even if "Title" field is empty.
// Also, save it as a variable to test against Errors() function.
UpdateContext({NewRecord: Patch(CSVCreationList, Defaults(CSVCreationList))});

// Error: "...record is incompatible type...".
ClearCollect(Errors, Errors(CSVCreationList))

and this is how the Errors collection looks:

Screen Shot 2019-11-26 at 8.51.10 AM.png

 

When you give Title the value of "" SharePoint does not consider that to be Blank.

View solution in original post

Highlighted
Frequent Visitor

Hi @AnneZC ,

 

You're right. I should've used Blank function then to test it properly.

Too bad I can't provide specific record to Errors function when working with SP list.
But I think, I don't have to, since Errors fetches first, encountered error from provided data source (SP list).

 

Final working example:

// Test Errors function. 
// Try saving multiple records to SP list with the same value ("Number" column should be unique).

// Dummy records
ClearCollect(RecordsToCreate, {Title: "1", Number: 10}, {Title: "2", Number: 10});

// Save to SP
ForAll(
    RecordsToCreate, 
    Patch(custom_sp_list, 
        Defaults(custom_sp_list),
        {Title: RecordsToCreate[@Title], Number: RecordsToCreate[@Number]}
    )
);

// Collect errors
ClearCollect(Errors, Errors(custom_sp_list));

 

Results:

  • 1 record out of 2 saved to SP list, errors fetched.

SP list - saved 1 out of 2 recordsSP list - saved 1 out of 2 recordsErrors collection - "Number" must be uniqueErrors collection - "Number" must be unique

 

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (7,137)