5

I am hoping that someone else here has tried to do this successfully. I am trying to approve a list item via JavaScript using the REST interface. I know how to do it with CSOM, but in this scenario I am crossing site collection boundaries and CSOM won't let you do that. I have tried setting _ModerationStatus, _moderationstatus, ows_ModerationStatus, and 'Approval Status' to 0 but I keep getting an error that the column is not a valid column on the list item type. Does anyone know of something special that can be done to get to some of the 'special' fields on a list item? My test code for reference.

function example() {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        processData: false,
        beforeSend: function (xhr) {
            xhr.setRequestHeader("If-Match", "*");
            xhr.setRequestHeader("X-HTTP-Method", 'MERGE');
        },
        url: "http://myserver/sites/full/path/to/site/_vti_bin/listdata.svc/MyList(1)",
        data: "{'ows_ModerationStatus':0}",
        dataType: "json",
        error: function (xhr) {
            alert(xhr.status + ": " + xhr.statusText);
        },

        success: function () {
            alert("success");
        }
    });
}

The exact error I am getting is:

"Error processing request stream. The property name 'ows_ModerationStatus' specified for type 'Microsoft.SharePoint.DataService.MyCustomItem' is not valid."

5

It does not seem possible to approve a list item since _ModerationStatus property is not exposed by REST in SharePoint 2010.

But, Approving/Rejecting could be performed with SharePoint SOAP services as demonstrated below:

function approveItem(webUrl,listTitle,itemId) {
   $().SPServices({
      webURL : webUrl, 
      operation: "UpdateListItems",
      listName: listTitle,
      ID: itemId,
      batchCmd: "Moderate",
      valuepairs: [["_ModerationStatus", "0"]],
      completefunc: function (xData, Status) {
        console.log(xData.responseXML); 
      }
   });


}



approveItem('http://intranet.contoso.fi/news','Documents',9);
  • 1
    That seems to be my conclusion as well. Too bad. – Lane Goolsby Mar 12 '14 at 18:32
  • And what about Sharepoint 2013 ? Any ideas ? – Tito Jan 27 '16 at 13:20
0

Use OData__ModerationStatus with SP2013 REST API (note: 2 _ between OData and ModerationStatus)

  • I am using this to approve list items and it is working. I'm using the 2013 api endpoint, so that might be the difference. Otherwise, not sure why someone voted it down, as far as I can tell this is correct. – Rothrock Dec 8 '16 at 16:12

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.