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:
Steps to recreate:
// 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)));
Solved! Go to Solution.
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:
When you give Title the value of "" SharePoint does not consider that to be Blank.
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:
When you give Title the value of "" SharePoint does not consider that to be Blank.
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:
SP list - saved 1 out of 2 records
Errors collection - "Number" must be unique
User | Count |
---|---|
120 | |
86 | |
83 | |
74 | |
69 |
User | Count |
---|---|
215 | |
179 | |
140 | |
108 | |
83 |