0

This issue only manifests on SharePoint online site.

I am able to do adds and updates to the list without issue until trying to update the user type Employee. Previously, for my on-prem customers I have added Id eg EmployeeId to the user column Employee and passed the foreign key (userid) to the list containing the people type field with success.

Now on our online SP I get a failure when trying to update a user. Error processing request stream. The request should be a valid top-level resource object.

enter image description here

EDIT: single entries only;

enter image description here

When pulling the list item the JSON property for Employee is:

...
<content type="application/xml">
    <m:properties>
        <d:EmployeeId m:type="Edm.Int32">3642</d:EmployeeId>
...

Hard-coding the item properties using my userid of 31: (If I remove the EmployeeId this works)

var itemProperties = {
    EmployeeId : 31,
    CurrentProject: 'currentproject'
};

updateListItem(
    myWebUrl()
    , "DSRMB"
    , id
    , itemProperties
    , function (success) {
        console.log('item has been updated');
    }
    , function (error) {
        console.log(JSON.stringify(error));
    }
);   

no magic here included just in case or TL;DR

function updateListItem(webUrl, listName, itemId, itemProperties, success, failure) {
    getListItemById(webUrl, listName, itemId, function (item) {

        $.ajax({
        type: 'POST',
        url: item.__metadata.uri,
        contentType: 'application/json',
        processData: false,
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-HTTP-Method": "MERGE",
            "If-Match": item.__metadata.etag
        },
        data: JSON.stringify(itemProperties), 
        success: function (data) {
            success(data);
        },
        error: function (data) {
            failure(data);
        }
    });

},
function (error) {
    failure(error);
});

}

function getListItemById(webUrl, listName, itemId, success, failure) {
    var url = webUrl + "/_vti_bin/listdata.svc/" + listName + "(" + itemId + ") ";

    $.ajax({
        url: url,
        async: gMMTasync,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            success(data.d);
        },
        error: function (data) {
            if (data.responseJSON) {
                if (listName !== "UserInformationList") {
                    failure(data.responseJSON.error);
                } else {
                    console.log("getListItemById No data returned for ID: " + itemId);
                }
            }

        }
    });
}
4
  • Is the person column marked to allow multiple selections? The format for setting a multi-user field is different than a single-user field. Also, while is does still work, the listdata.svc is considered deprecated, you should really be using the Items REST API.
    – willman
    Commented Feb 20, 2020 at 19:42
  • 'SinglePersonColumnId':9, 'MultiPersonColumnId':{'results':[9,12]}}
    – willman
    Commented Feb 20, 2020 at 19:44
  • Single entry only. Updated question Commented Feb 20, 2020 at 20:09
  • 1
    Are you certain that "Employee" is the internal name of the Field? sympmarc.com/2009/12/11/…
    – willman
    Commented Feb 20, 2020 at 20:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.