0

I have a form that has a few multi-select choice fields. When I try to add an item, I get an unusual error below. I am using the Vue.js framework.

"value: "A node of type 'StartArray' was read from the JSON reader when trying to read a value of a property; however, a 'PrimitiveValue' or 'StartObject' node was expected."

Here's the code and the fields that are multi-select.

 $.ajax({
url: fullUrl,
method: "POST",
data: JSON.stringify({
  '__metadata': { 'type': 'SP.Data.RegistryListItem' },
  'Register': that.register,
  'RiskRegister': that.nextIndex,
  'Reopen': that.formatDate(that.reopen),
  'RiskOrIssue': that.riskOrIssue,
  'Status': that.status,               //<---multi-select choice field
  'ProblemT': that.probTitle,
  'ProblemStatement': that.problemStatement,
  'TaskOwner': that.taskOwner,
  'RiskOwner': that.riskOwner,
  'ResponseOwner': that.responseOwner    //<--- multi-select choice field
}),
headers: {
  "accept": "application/json;odata=verbose",
  "content-type": "application/json;odata=verbose",
  "X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function(){
  alert("Item Added!");
},
error: function(data){
  console.log(data);
}   
});    

How can I solve this issue?

Thank you!

3 Answers 3

1

Here is an working example to set value of a Multi-select Choice field. Insert it in a Script Editor and test :

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
  SetMultiChoice();
});
function SetMultiChoice() {

var listName = "ListTitle";

 var itemDetails = {
    "__metadata": { "type": 'SP.Data.GZTickerListItem' },
    "Column_Internal_Name":{"results": ['A', 'B']}  // Multi Choice Column where A & B are the choices selected 

};
$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
    type: "POST",
    contentType: "application/json;odata=verbose",
    data: JSON.stringify(itemDetails),
    headers: {
        "Accept": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    success: function (data) {

        //Perform Some Actions
    },
    error: function (data) {
        console.log(data);
    }
});
}

</script>

To get the _metadata value specific to your list use the below URL in your browser and search for ListItemEntityTypeFullName:

https://site-url/_api/web/lists/GetByTitle('ListName')/?$select=ListItemEntityTypeFullName

Let me know if this helps.

3
  • Is this correct? 'Status': {'__metadata': {'type': 'Collection(Edm.String)'}, 'results':that.Status} I get an error still. that.Status is an array from my multi select drop down Commented Nov 25, 2019 at 0:32
  • Is it different for SharePoint Online? Commented Nov 25, 2019 at 18:29
  • Tested it in my SharePoint online site and Updated the answer. Please check and let me know if this helps. Commented Nov 26, 2019 at 6:26
0

Try to set your multi-select choice fields in below format:

'Status': {'__metadata': {'type': 'Collection(Edm.String)'}, 'results':['Status 1', 'Status 2', 'Status 3']}

OR Simply try using:

'Status': { 'results':['Status 1', 'Status 2', 'Status 3'] }

Check my answer given at SharePoint Multiselect Choice field Saving using PnPjs for easy format.

Similar Questions:

  1. SP 2013 - Updating a multi-value lookup field via the REST API
8
  • I tried doing that but I get this error now value: "Incompatible type kinds were found. The type 'Collection(Edm.String)' was found to be of kind 'Collection' instead of the expected kind 'Primitive'." Commented Nov 25, 2019 at 0:31
  • Have you tried the 2nd/simple solution in my answer? Is data type of your column is Choice or Lookup field? Commented Nov 25, 2019 at 2:15
  • Yes I did. It's a choice field allowing multiple selections. 'Status': {'__metadata': {'type': 'Collection(Edm.String)'}, 'results':that.Status} that.Status is an array. Is that set up wrong? Commented Nov 25, 2019 at 3:39
  • If you are passing an array then check my answer given at: sharepoint.stackexchange.com/questions/267789/…. This should work for you. Commented Nov 25, 2019 at 3:46
  • Don't pass the type in metadata. Just pass the results array. Commented Nov 25, 2019 at 3:47
0

Sample test script:

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script>
$(document).ready(function() {
CreateNew();
function CreateNew() {
    var listName = "11/25";

    CreateListItemWithDetails(listName, _spPageContextInfo.webAbsoluteUrl, function () {
        alert("New Item has been created successfully.");
}, function () {
     alert("Ooops, an error occured. Please try again.");
});
}

function CreateListItemWithDetails(listName, webUrl,  success, failure) {

    var item = {
        "__metadata": { "type": 'SP.Data.1125ListItem' },
        "OData__x0063_1":{"results": ['t1', 't2']}

    };

    $.ajax({
        url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {

            success(data);
        },
        error: function (data) {
            failure(data);
        }
    });
}


})
</script>
1
  • I really appreciate your help on this. You are passing in a hard-codded array. I am passing in what I get from the multi-select drop down which is in this form in vue that.status. It holds the array values. Can the array be passed that way? I have everything you have, except how I pass the array but I get an error. Commented Nov 27, 2019 at 12:44

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.