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

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
AnneZC
Helper I
Helper I

Hi @Anonymous 

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
AnneZC
Helper I
Helper I

Hi @Anonymous 

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.

Anonymous
Not applicable

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
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,262)