Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In an event receiver, Item Was Updated. I want to Compare the Moderation status on ListItems to perform some functionality.This is just some of the code.

SPList list = web.Lists["DocLib"];
SPListItem item = list.GetItemById(listItemID);

var moderationStatus = item["_ModerationStatus"] as string;

if(moderationStatus == SPModerationStatusType.Approve.ToString())
   //Do stuff

So I should be able to get the values from this to make the comparison in a later stage:

string beforeStatus = properties.BeforeProperties["_ModerationStatus"] as string;
string afterStatus = properties.AfterProperties["_ModerationStatus"] as string;

In Document Libraries we know that:

  • BeforeProperties = Original Value.
  • AfterProperties = Changed Value.

But beforeStatus and afterStatus is null.

Does someone have any tips of other ways to Compare the values? I have even tried to take get the value form "ItemUptading" to get the value before it updates.

Thanks for reading.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Not sure if this is the cause of your problem but...

For documents, Before and After properties are guaranteed for post events, such as ItemUpdated, but Before properties are not available for post events on list items

Reference:http://msdn.microsoft.com/en-us/library/ms463479.aspx

If this is your scenario you may want to use properties.ListItem and use that to compare the values. This article may help you further... http://www.synergyonline.com/Blog/Lists/Posts/Post.aspx?ID=122

share|improve this answer
    
So the problem lies with the accessing of the parameter. I have to use the "vti_" named parameters for it to work for title, but i can't use the vti_doclibmodstat to access the ModerationStatus. Have any toughts? - title --> vti_title - _ModerationStatus --> vti_doclibmodstat –  George Norberg Oct 14 '13 at 10:55

So me and a friend (Mattias Åhlin) at work solved the issue. To get the functionality as with before and after properties and if() statments with the same result as the code does down bellow.

So to answer my question, one of the problems with Before and After properties with versioning is that it's not 100% complete. In some cases the before value (of moderationStatus) is null, when it before value is 2 or pending it's OK, but when it's 3 or draft the before value is null.. just one example.

This might help someone who's struggling with the same issue i had.

The Code:

if (properties.AfterProperties["vti_doclibmodstat"] != null)
        {
            var after = (SPModerationStatusType)int.Parse(properties.AfterProperties["vti_doclibmodstat"].ToString());
            switch (properties.ListItem.ModerationInformation.Status)
            {
                case SPModerationStatusType.Approved:
                    switch (after)
                    {
                        case SPModerationStatusType.Draft:
                            break;
                        case SPModerationStatusType.Pending:
                            break;
                        default:
                            break;
                    }
                    break;
                case SPModerationStatusType.Denied:
                    switch (after)
                    {
                        case SPModerationStatusType.Draft:
                            break;
                        case SPModerationStatusType.Pending:
                            break;
                        default:
                            break;
                    }
                    break;
                case SPModerationStatusType.Draft:
                    switch (after)
                    {
                        case SPModerationStatusType.Draft:
                            break;
                        case SPModerationStatusType.Pending:
                            break;
                        default:
                            break;
                    }
                    break;
                case SPModerationStatusType.Pending:
                    switch (after)
                    {
                        case SPModerationStatusType.Approved:
                            break;
                        case SPModerationStatusType.Denied:
                            break;
                        case SPModerationStatusType.Draft:
                            break;
                        case SPModerationStatusType.Pending:
                            //hej
                            break;
                        default:
                            break;
                    }
                    break;
                default:
                    break;
            }
        }
        base.ItemUpdating(properties);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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