none
"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." RRS feed

  • Question

  • Here is my ajax code to set multi choice field:

     $.ajax({
    url: fullUrl,
    method: "POST",
    data: JSON.stringify({
      '__metadata': { 'type': 'SP.Data.AuditItem' },
      'Register': that.register,
      'RiskRegister': that.nextIndex,
      'Reopen': that.formatDate(that.reopen),
      'RiskOrIssue': that.riskOrIssue,
      'Locations': that.locations,               //<---multi-select choice field
      'ProblemT': that.probTitle,
      'ProblemStatement': that.problemStatement,
      'TaskOwner': that.taskOwner,
      'RiskOwner': that.riskOwner,
      'Auditor': that.auditor    //<--- 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);
    }   
    });    

    For multi choice field, happen the error below, please help me how to solve:

    "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."

    Thanks in advance

    Thursday, November 28, 2019 1:22 AM

Answers

  • Hi zhuw12,

    Here is a code snippet to set multiple choice field, should be a array collection:

    <script type="text/javascript">
    	   var locations = ['Locations1','Locations3'];
    	   var Auditors =  ['Auditor1','Auditor3'];
           var item = {  
    		            "__metadata": {  
    		                "type": 'SP.Data.MyListListItem'
    		            },  
    					   "Title":'Test',
    		               "Locations": { '__metadata': { 'type' : 'Collection(Edm.String)'}, results: locations },
    		               "Auditor": { '__metadata': { 'type' : 'Collection(Edm.String)'}, results: Auditors }
    		
    		
    		        }; 	  
      $.ajax({  
                        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('MyList')/items",  
                        method: "POST",  
                        contentType: "application/json;odata=verbose",  
                        data: JSON.stringify(item),  
                        async: false,  
                        headers: {  
                            "Accept": "application/json;odata=verbose",  
                            "X-RequestDigest": $("#__REQUESTDIGEST").val() 
                        },  
                        success: function(data) {  
                            alert('The Request has been successfully Added'); 
                        },  
                        error: function(jqXHR, textStatus, errorThrown) {  
    						console.log(jqXHR.responseText);
    						alert('Error');  
                        }  
                    });  
    </script>
    

    Thanks

    Best Regards


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

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Proposed as answer by HarshalGite Thursday, November 28, 2019 7:51 AM
    • Marked as answer by zhw12 Friday, November 29, 2019 2:11 AM
    Thursday, November 28, 2019 7:29 AM