none
Create item with REST-api containing a required lookup field RRS feed

  • Question

  • Hi,

    why do i not get an error-code, when i create a list-item with the REST-api, where the item contains a required lookup-field and the value (id) for this field does not exist.

    Problem: The item will be created with no error response, but the value of the required lookup-field will be empty, because the id does not exist.

    This should not be possible imo. Is there an option to check/avoid this ?

    Monday, April 16, 2018 7:18 AM

All replies

  • Hope the below helps you

    https://sharepoint.stackexchange.com/questions/110643/sharepoint-2013-rest-create-list-item-with-user-field-and-lookup-field


    Please remember to click Mark as Answer on the answer if it helps you

    Monday, April 16, 2018 10:30 PM
  • Hi Thomas Stessl,

    I have reproduced your issue. I got the same results as you got.

    As a workaround, add custom function to validate the required data before saving the list item.

    Best Regards,

    Linda Zhang


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Tuesday, April 17, 2018 7:53 AM
    Moderator
  • But this would raise the workload on the server, when i always have to check if the lookup-item exists.
    We often create multiple items with an import-process via webservices, so with this workaround it would take much much longer.

    Maybe there will be a fix in the future.


    Thursday, April 19, 2018 8:30 AM
  • Hi Thomas Stessl,

    When we save an item from the SharePoint UI, there is built-in script (PreSaveItem function) to validate the entries.

    If using the REST API to create an item, it will not validate the entries as we do not call any script for that.

    You need to add validation to the code.

    Best Regards,

    Linda Zhang


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Friday, April 20, 2018 2:11 AM
    Moderator
  • But in this case i have to check if the item for the lookup exists (+1 query on the server).

    Still, i think this should be fixed, so the item will not be created in the first place with missing required fields.

    Monday, May 28, 2018 1:15 PM