2

I am using pnpjs to add items to a list like so:

this.spClient.web.lists.getByTitle(this.spList).items.add(requestList);

If requestList has items that do not pass column validation of the Sharepoint list I receive an exception with only a very generic error message:

{"odata.error": {
     "code": "-2130575163,Microsoft.SharePoint.SPListDataValidationException",
     "message": {
         "lang": "en-US",
         "value": "List data validation failed."
      }
}}

How can I retrieve the information which fields failed validation?

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest#working-with-list-items-by-using-rest suggests the information should be available and if I try to add such an erroneous element manually in Sharepoint itself the form marks the errors in red.

2 Answers 2

0

Go into the network tab in Chrome dev tools (or else use Fiddler), find the REST call and inspect the raw response from the server. For 400-type errors you'll typically see a more detailed description of the error.

1
  • Thanks. Unfortunately, I get a 500 error and that is an exception. Checking with Fiddler the response doesn't contain anything more than what I show in my question.
    – mplwork
    Dec 18, 2019 at 12:24
0

You can add the item using PnPjs like this:

private PnPAddItem():void
{
  sp.web.lists.getByTitle("Jerry").items.add({
    Title: "NewItemAddedTitle"
  }).then((iar: ItemAddResult) => {
    console.log(iar);
});

}

You can console.log(iar) response in the console to see which field failed validation and you could also check the Network tab to see reponse status and request details:

enter image description here

7
  • This doesn't work. I get a 500 response, which throws an exception. So the then part isn't taken at all. try/catch doesn't lead to more than what I showed in my question. But thanks for the then, I hadn't thought of it.
    – mplwork
    Dec 18, 2019 at 12:26
  • Can you please create a new list and then just add a item with default Title field to see if it works ? As the script above won't have problem in my side.
    – Jerry
    Dec 18, 2019 at 12:37
  • Sorry, I can't test this right now. I am sure the then branch will be taken if there is no error. The point here is a field that fails column validation. In that case I get a javascript exception which I can handle with try/catch of course. But there is only generic information in the exception itself.
    – mplwork
    Dec 18, 2019 at 13:31
  • Please test if you have time and updates :)
    – Jerry
    Dec 19, 2019 at 0:55
  • Could you elaborate what this test is supposed to show? I don't have any problem with adding a list item. It is only if there is a validation for a certain field and that validation indicates a problem with the data provided that I don't get sufficient information. So how should updating trivial Title field provide any insight?
    – mplwork
    Dec 19, 2019 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.