1

Is there an easy way to retrieve item approval status (moderationStatus) inside the edit form? During display of edit form I need to know wheather the currently edited item was approved or not. I see that the information is not reflected in a hidden column or else. I have the following ideas:

  • Custom flag column that indicates if the item was approved.
  • Get the current item via js rest call and check OData__ModerationStatus.

I just want to know if there is an easier way to get the moderationStatus of the item I am editing.

Thank you!

4

Since Content Approval status is stored in List Item (_ModerationStatus) I would recommend to leverage any client APIs (JSOM, REST or SOAP) for that purpose.

How to retrieve content approval status using client APIs

JSOM

function getListItemModerationInfo(listId,itemId,success,error)
{
   var ctx = SP.ClientContext.get_current();
   var web = ctx.get_web();
   var list = web.get_lists().getById(listId);
   var item = list.getItemById(itemId);
   ctx.load(item);

   ctx.executeQueryAsync(
      function() {
          var moderationInfo = {};  
          moderationInfo.Status = item.get_item('_ModerationStatus');
          moderationInfo.Comments = item.get_item('_ModerationComments');
          success(moderationInfo); 
      },
      error);
}

Usage: how to retrieve content approval status of list item in edit form

var listId = _spPageContextInfo.pageListId; //current List Id
var itemId = parseInt(GetUrlKeyValue('ID')); //current Item Id

getListItemModerationInfo(listId,itemId, 
   function(info){
       console.log(info.Status);
   },
   function(sendera,args){
       console.log(args.get_message());
   });

REST

Endpoint: /_api/web/lists/getById('<guid>')/items(<id>)?$expand=FieldValuesAsHtml

function getListItemDetails(webUrl,listId,itemId)
{
    var url = webUrl + "/_api/web/lists/getById('" + listId + "')/items(" + itemId + ")?$expand=FieldValuesAsHtml";
    return $.ajax({
        url: url,
        method: "GET",
        contentType: "application/json;odata=verbose",
        headers: {
           "Accept": "application/json;odata=verbose"
        }
    });
}

Usage

var listId = _spPageContextInfo.pageListId;
var itemId = parseInt(GetUrlKeyValue('ID'));
getListItemDetails(_spPageContextInfo.webAbsoluteUrl,listId,itemId)
.done(function(data)
{
    var moderationStatusName = data.d.FieldValuesAsHtml['OData__x005f_ModerationStatus'];
    console.log(moderationStatusName);
})
.fail(function(error){
    console.log(JSON.stringify(error));
});
  • 1
    Probably the best solution and the correct one :) But couldn't you check the property of WPQ2FormCtx.ListData._UIVersionString , where approved would be 1.0, 2.0 etc? – Anders Aune Dec 15 '14 at 22:47
  • 1
    Wow, thank you very much. This is a full featured answer! I've also used a REST call to get the modStat to get this information. So your answer tells me I'm not doing wrong. – Worn Dec 16 '14 at 8:22
  • Great, glad it helped you :) – Vadim Gremyachev Dec 16 '14 at 12:14
  • Anders, thanks! That's an interesting idea to utilize that property, will check it also.. – Vadim Gremyachev Dec 16 '14 at 12:17

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.