2

I want to update a list item with People and Group column.

The list has 4 columns:

  • Title
  • Description
  • ProsessOwner
  • ProsessContributer

I am not able to add/update through a REST POST method, since I am getting an error on these two columns: ProsessOwner, ProsessContributer. If i remove them both from the query string, the rest query works.

This is the returned 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.

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 only single value selection and the REST query 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 as soon as I changed column back to the previous setting ( allow multiple selections), and change the REST query to 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.

  • I fixed this with sending an array for multiple selection like this: {results: [10,11]}; – user3629354 Jun 27 '16 at 10:08
  • Hey please take a look to my answer in case it also works and can be marked as alternative answer, thanks :) – Alberto S. Apr 15 at 9:34
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.

| improve this answer | |
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

| improve this answer | |
  • 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
0

here is a solution for you, in scenarios you want to update a people column [mypeoplecol] through rest / spfx:

  • Single value people column: [mypeoplecol]Id = X, where X is a [number] type value.
  • Multiple value people column: [mypeoplecol]Id = {results:[X, Y, ...]}, where X, Y, ... are [number] type value.

Take into account that you may need to leverage the ensureUser service, in order to ensure the target(s) user(s) do have and ID on that site.

| improve this answer | |

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.