sarbashis
sarbashis

Reputation: 175

How to fix error in SharePoint while adding users in multi person or group field(people only)

I am trying to add multiple users in a multi person or group field(people only) in a Sharepoint list, But I am getting below error message

"An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected."

I have used REST call to add items in Sharepoint list, items are being added properly when I remove multi people column in the rest call.

$scope.formData = { Title: $scope.codeNumber, SBMTestId:{ "results": [17,15] } }
                var data = JSON.stringify($scope.formData);
                var listName = "Test";
                data = data.replace(/[{}]/g, '');
                var datavalue = "{__metadata:{'type':'SP.Data.TestListItem'}," + data + "}";
                $http({
                    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('" + listName + "')/items",
                    method: "POST",
                    headers: {
                        "Accept": "application/json;odata=verbose",
                        "Content-Type": "application/json;odata=verbose",
                        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                        "X-HTTP-Method": "POST"
                    },
                    data: datavalue
                }).then(function (response) {
           alert("Go on!");

        }, function (response) {
                    alert("Something is wrong. Please try after sometimes");
                }); 

The error message is below:

data:
  error:
    code:"-1, Microsoft.SharePoint.Client.InvalidClientQueryException"
    message:
    lang:"en-US"
    value:"An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected."

Upvotes: 0

Views: 2066

Answers (1)

Lee
Lee

Reputation: 5493

Try below JSON data format.

{
            "__metadata": { "type": "SP.Data.MyList2ListItem" },
            "Title": "RestApiCreated",
            "MultiUsersId": { "results": ["12", "23"] }
        }

Upvotes: 3

Related Questions