6

This is how SP presents Version History:

Version History

I use this URL to get file history:

http://portal:34798/Documents/_api/Web/GetFileByServerRelativeUrl('/Documents/Documents/Tests/Tests_TextFile.txt')/Versions

Server response is a collection of objects:

{
"__metadata": {
  "id": "http:\/\/portal:34798\/Documents\/_api\/SP.FileVersionc5f4d85f-501a-421b-a3cb-446f090daa15",
  "uri": "http:\/\/portal:34798\/Documents\/_api\/SP.FileVersionc5f4d85f-501a-421b-a3cb-446f090daa15",
  "type": "SP.FileVersion"
},
"CreatedBy": {
  "__deferred": {
    "uri": "http:\/\/portal:34798\/Documents\/_api\/SP.FileVersionc5f4d85f-501a-421b-a3cb-446f090daa15\/CreatedBy"
  }
},
"CheckInComment": "88979",
"Created": "2014-08-20T11:17:14Z",
"ID": 2048,
"IsCurrentVersion": false,
"Size": 10,
"Url": "_vti_history\/2048\/Documents\/Tests\/Tests_TextFile.txt",
"VersionLabel": "4.0"
}

Approval Status information is missing in response. Question is how to get Approval Status for Version History items?

1
  • I cannot test this, as I have neither a library with moderation, nor the time to set it up, but perhaps checking the properties of the list item itself.
    – wjervis
    Aug 20, 2014 at 13:42

2 Answers 2

0

Take this answer with a grain of salt but it seems that you cannot do this with REST. However, I have found an answer from JSOM if that might help. This answer was taken from this link.

Here is the full code that gets and sets (optional) approval status (Possible values for this.oListItem.get_item('_ModerationStatus'): 0 - "Approved", 1 - "Denied", 2- "Pending"):

<script type="text/javascript" src="/jquery-1.10.2.min.js"></script>
<script src="/jquery.SPServices-2013.02a.js" type="text/javascript"></script>
<script type="text/javascript">

$(document).ready(function () { 
    ExecuteOrDelayUntilScriptLoaded(loadConstants, "sp.js"); 
});

function loadConstants() {

    var userid= _spPageContextInfo.userId;
    var requestUri = _spPageContextInfo.webAbsoluteUrl + 
                     "/_api/web/getuserbyid(" + userid + ")";
    var requestHeaders = { "accept" : "application/json;odata=verbose" };
    $.ajax({
      url : requestUri,
      contentType : "application/json;odata=verbose",
      headers : requestHeaders,
      success : onSuccess,
      error : onError
    });

    function onSuccess(data, request){
        var loginName = data.d.Title;

        //get current (selected) list item id
        var docurl = document.URL;
        var beginindex = docurl.indexOf('?ID=') + 4;
        var endindex = docurl.indexOf('&Source=');
        var itemid = docurl.substring(beginindex, endindex);
        var ctx = new SP.ClientContext("your site url");
        var oList = ctx.get_web().get_lists().getByTitle('your list name');
        this.oListItem = oList.getItemById(itemid);

        var appStatus = "";
        ctx.load(this.oListItem);

        ctx.executeQueryAsync(Function.createDelegate(this, function () {
            //get approval status
            appStatus = this.oListItem.get_item('_ModerationStatus');
            //set approval status to Approved (0)
            this.oListItem.set_item('_ModerationStatus', 0);
            this.oListItem.update();

            ctx.executeQueryAsync(
                Function.createDelegate(this, this.onQuerySucceeded),
                Function.createDelegate(this, this.onQueryFailed)
            );

        }), function (sender, args) { 
              alert('Error occured' + args.get_message());
        });
    }
    function onError(error) {
        alert("error");
    }       
}

</script>
0

TO asked for REST, I found that if you request the item, not the file, the approve status and comments will be there.

You got to ask for internal names in select/exapand, meaning: _ModerationStatus and _ModerationComments

But, the trick it - the response does not have these columns. Instead, they will come back named: OData__x005f_ModerationStatus and OData__x005f_ModerationComments.

Here is an example request for specific item:

".../_api/web/lists(guid'...')/items([item id])/FieldValuesAsText"

the results will be in item.OData__x005f_ModerationStatus.

this will return moderation status as text (approved, rejected, pending).

If you request for FieldValuesForEdit you will get 1,2,3 instead.

Ofcourse, you can do this on the list to get all items moderation info at once.

I don't think you can do it on the file object - you got to get to it from the list item point of view.

Your Answer

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

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