1

iam trying to update my list item with "People and Group" column without any luck. It is a simple list with 4 columns/fields (Title, Description, ProsessOwner, ProsessContributer), and iam not able to run REST POST method with this two columns: ProsessOwner, ProsessContributer. If i remove them both from the query string i get success post. And item is added to my list with only title and description.

iam getting error below:

A node of type 'PrimitiveValue' was read from the JSON reader when trying to read the entries of a feed. A 'StartObject' or 'EndArray' node was expected.

And my code :

 $scope.saveNewPage = function () {
        var err = false;
        var title = $scope.newPage.title;
        var descr = $scope.newPage.description;
        var pOwnerID = { 'results': [processOwnerID,11] };
        var pContrID = { 'results': [processContributerID,11] };
        var data = { "Title": title, "Description": descr, "ProsessOwner": pOwnerID, "ProcessContributer": pContrID };

        ppService.addnewPage(data).then(function (data) {
            close(data.d.Id);
        }, function (error) {
            console.log('Feilet med å opprette ny Side');
        });

    }

var addnewPage = function (data) {
        var addData = {
            __metadata: { 'type': 'SP.Data.GNPagesListItem' },
            Title: data.Title,
            Description: data.Description,
            ProsessOwner: data.ProsessOwner,
            ProcessContributer: data.ProcessContributer
        };

        var url = listEndPoint + "/GetByTitle('GNPages')/Items";
        return baseSvc.postRequest(addData, url);
    };

        var postRequest = function (data, url) {
        var deferred = $q.defer();
        $http({
            url: baseUrl + url,
            method: "POST",
            headers: {
                "content-Type": "application/json;odata=verbose",
                "accept": "application/json;odata=verbose",
                "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
            },
            data: JSON.stringify(data)
        })
            .success(function (result) {
                deferred.resolve(result);
            })
            .error(function (result, status) {
                deferred.reject(status);
                console.log(result)
            });
        return deferred.promise;
    };

Edit

I just edited my list "Person or Group" column setting to only allow single selection. and it worked fine with the code below:

 var addnewPage = function (data) {
        var addData = {
            __metadata: { 'type': 'SP.Data.GNPagesListItem' },
            Title: data.Title,
            Description: data.Description,
            ProsessOwnerId: 10,
            ProcessContributerId: 11
        };

        var url = listEndPoint + "/GetByTitle('GNPages')/Items";
        return baseSvc.postRequest(addData, url);
    };

But When i change column setting to allow multiple selections and send an array of id's like [10,11], i get the same error:

A node of type 'PrimitiveValue' was read from the JSON reader when trying to read the entries of a feed. A 'StartObject' or 'EndArray' node was expected.

Blockquote

  • I fixed this with sending an array for multiple selection like this: {results: [10,11]}; – user3629354 Jun 27 '16 at 10:08
2

I guess you are missing something in this step.

var addData = {
__metadata: { 'type': 'SP.Data.GNPagesListItem' },
Title: data.Title,
Description: data.Description,
ProsessOwnerId: data.ProsessOwner,
ProcessContributerId: data.ProcessContributer
};

To update a people or group field, instead of ProsessOwner or ProcessContributer the nomenclature should be ProsessOwnerId and ProcessContributerId. Most of us will miss the suffix 'Id' with the internal name while updating a people or group filed. And the value for the field should be User Id of the user in the Site.

1

Seems like there is some mismatch in your JSON or data variable.

Please check whether for "data.ProsessOwner" and "data.ProcessContributer" you are getting correct ID's.

please refer this answer - Updating Lookup Values with the REST API

  • I fixed it like this for multiple values: {results: [10,11]}; , you need to send an array like this. or only an id of user. – user3629354 Jun 27 '16 at 10:06
  • Yes, you are right. – Rohit Waghela Jun 27 '16 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.