2
Vote

Current Version does not change when Content Approval is required

description

Hello,

Really like this solution :) so thanks for making this available to us all.

I'm using the "Content Approval Required" option for a library along with your solution, primarily I just want to use the Current Version field. Unfortunately after a document is Majorly Revised via the "Approve/Reject" task it does not update the Current Version field.

It'd be great if you could include/change the code to accommodate the Current Version field being updated with Content Approval Required switched on.

Hope that makes sense :) thanks again,

Jamie.

comments

rubenmiddel wrote Aug 11, 2016 at 12:52 PM

I Experienced the same issue with Major versions, the problem is that the new major version is not available in the _UIVersionString variable. To detect this version change on approval, we can use the vti_level value. This changes from 255 to 0 upon the approval of a new major version, it remains 2 when a major version gets published.
Code to fix it:
SPListItem item = properties.ListItem;

int beforeLevel = (int.TryParse(properties.BeforeProperties["vti_level"].ToString(), out beforeLevel) ? beforeLevel : -1);
int afterLevel = (int.TryParse(properties.AfterProperties["vti_level"].ToString(), out afterLevel) ? afterLevel : -1);

if (item["_UIVersionString"] != null && !string.IsNullOrEmpty(item["_UIVersionString"].ToString()))
{
    // If check in major version
    if ((beforeLevel == 255 && afterLevel == 1) || (beforeLevel == 2 && afterLevel == 2))
    {
        int major = int.Parse(item["_UIVersionString"].ToString().Split('.')[0]);
        int minor = int.Parse(item["_UIVersionString"].ToString().Split('.')[1]);
        minor = 0;
        major++;
        item["Current Version"] = string.Format("{0}.{1}", major, minor);
    }
    else
    {
        item["Current Version"] = item["_UIVersionString"].ToString();
    }
}

twofries wrote Jan 24 at 10:56 AM

Hi,

I am also having this issue and would like to resolve it.

Excuse my ignorance, but where do I need to modify this code?

Thanks,

Pete