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

橙三吉。 提交于 2019-12-24 21:23:52

问题


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

回答1:


Try below JSON data format.

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


来源:https://stackoverflow.com/questions/56010089/how-to-fix-error-in-sharepoint-while-adding-users-in-multi-person-or-group-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!