2

I have a document library with major and minor versioning enabled. Within this library we have documents that most people in the business need to see both minor and major versions, although only certain people can edit them.

What I am trying to do is have it so that there is a view which shows only the major versions of the documents, even if there is a minor version in existence and another view which shows all the minor (draft) versions of the documents. Essentially having a draft library view and a published library view.

Is this possible?

I am using SP2013

Thanks

4

Sean

It is possible to do this however you will need a workflow to run behind the scenes to create a sneaky URL with some specific elements in it to show the latest Published version of any document - i.e. the Major release.

Basically the way SharePoint manages previous version of documents is in using a set of hidden folders of all the previous versions. The first Published version of any document gets set up as this:-

http://server-name.com/subsite-name/_vti_history/512/library-name/file-name

as you can see there is an extra bit in the ( /_vti_history/512/ ) which is used to denote the first published version. So if you need to access version 1.0 put that extra bit in the URL BEFORE the library name, then paste it in a browser and see what happens. If you wnat version 2.0 of a document, you'll need to change the '512' in 1024. Version 3.0 becomes 1536, v4.0 uses 2048 and so on.

Thus if you create a workflow on your document, you can build a string using the URL of the library, and the integer from the version number, and then times that by 512, and pull the lot together and place it into a new Hyperlink field (you can make it with a 'click here for Published version' tag as well), then include that in your View. It's a bit of a work up but SharePoint hides this kind of detail from the normal way of working.

We've used it in a Formal Document Management system we developed for 2007 and 2010 versions of SharePoint (we are working on a 2013 version now) which is often used by companies looking to manage Procedures, Policies, Forms etc for ISO 9000/14000 and similar Compliance standards.

If you need further guidance, do please come back to me.


Extra guidance

Sean

You need to bring a number of things together at this and I'll try and explain what you need to establish and set it up.

  1. A new field (URL type) in the library that is used for the URL link to the 'Latest Published (current) document' (I'd think about using a hidden field on the document, but use it for the View display only.
  2. A Workflow in SharePoint Designer which only runs when the document is Published or the version ends with a 'zero' (perhaps it could run upon change, but then pauses until the Status value field hits 'Published', thus it only runs once every Publishing cycle.
  3. Change the appropriate View(s) and add the URL field to that

Create the Upon Change WF for the library, and in that create a VAR string builder in it which adds:

  • the prefix of the (server/subsite/_vti_history/) PLUS (the Published number which will be 1.0/2.0/3.0 etc, and multiplies that by 512) PLUS a forward slash then the suffix of the library name and the file name PLUS (and this is very important - immediately after the filename.docx or whatever, you add a 'comma' then a space and finally add the text or words you want to use in the View as the text to ‘Click On’ to launch the document.

Check that this VAR works directly by manually creating a link to a known Published document etc but strip off the ', Link Here' stuff before you test it.

Then in the WF you need an Update File action which sets the URL field to be the string,

I'd also add some 'Log to History's in the WF which record the value of the VAR you are creating and string etc. You might also need to check things like CheckIn/Out and the impact on the Versioning itself when you run the WF!!

Also beware of Looping as that can cause a problem with 'upon change' WF's and maybe the use of a hidden flag to stop things would be useful as well.

I hope the above helps. If you have any further questions perhaps a personal message or chat might be best? Alan C.


Even more guidance

Sean - I've done a bit more messing since I last emailed and there are some gotchas which I forgot about as I recreated the approach.

Firstly Check In / Out. If you have a WF that runs and needs to check out a document, because the server side of things takes a little time to catch up, you'll need to do a pause for perhaps a minute after you check things out. You can be lulled into thinking that you can use the 'wait for this field to = xxxx, however that's no use if you are controlling the document and it's checked out to you. Also if you try to add after the checkout a 'wait until the CheckedOutTo field has a value', then that never seems to work for me either. The bonkers part is if you have the CheckedOut To displayed in a View, once the WF starts it displays the name but the WF sits in a pausing mode and never progresses. Therefore a pause for 1 min does it for me.

Secondly, triggering the WF to run correctly. Unless you have a triggering mechanism (we use the HarePoint Wprkflow Scheduler as it is FOC), you'll need to have this WF set up as an 'Upon Change' WF. I'd put a 'Wait For XX to equal XX' at the start of it so that it runs once per cycle, and have that either looking for your Document Status or use a Wait for 'Approval Status' to be = '0;#Approved', thus it will initiate properly when the SP internal version has become 1.0/2.0/3.0/4.0 etc.

Thirdly, if you use an 'upon change' WF, as soon as it has run against the 'Approved & Published' document, it will try to run again, however this second time, it will hit the Wait For option of the Approval status as the status will previously have changed from 0 (Approved) to 3 (Draft).

With the above said, create the new URL field in the Library and add that to the Views as needed. In order to stop the field from displaying in the form, you will need to change which fields display on the Properties for the document. You will need to have selected Yes under the 'Allow Management of Content Types' under Advanced Settings for the library, and then you can set the field to be Hidden when you access the Content Type Information description for the document.

So for the WF itself you need:-

  1. A 'Wait for....' command as above
  2. A 'CheckOut command for the document.
  3. A 'Pause for 1/2 minutes'
  4. A line which sets a new Variable to be the URL string
  5. A line which records the Variable to the WF history Log
  6. A line that updates the Current Item's new URL field in the library
  7. A Checks In action for the document with a comment.

OK, so now for some detail.

  1. Can be achieved as suggested by using the 'Approval Status' option.
  2. Under the List Actions group select the 'Check Out' item action, make certain that the Current item is selected.
  3. As suggested put a 1 or 2 min wait to allow the CheckOut elements to sort themselves out.
  4. Add a Set Workflow Variable. Click on where it says 'workflow variable' and use a sensible VAR name. Make certain you choose the type as String as this allows a combination string to be created. enter image description here

Once you've created the VAR title, you should click on the 'value' and then on the elipses button (it is the three dots in a row)
enter image description here and in there type in the following string:-

http://yourservername/subsite/_vti_history/CurrentItem: UI Version/Lists/LibraryName/Current Item: Name, WORDS 

enter image description here

Note - if the WF is going to run immediately after a version has become Published & Approved and has a suffice of zero, you can use the document's 'UI Version' field which is automatically a multiple of 512 here. As I mentioned previously the ','(comma) and the following space followed by your 'WORDS' are used to display a clickable link once you add the column to the View.

  1. As suggested I'd then use a 'Log (Variable as a String)' to the WF history at this point in order to check when it runs that you are getting it set correct.
  2. Now you need to add the Variable to the new URL field you've added to the library. As I said this should be a URL type field, and probably is one that you would want to have hidden from the form itself, just having it displayed in a View. Use the 'Update List Item' action, and then set the field to be the VAR.

enter image description here

  1. Finally add a Check In action then Save and Publish the WF.

You might need to tweak it a bit but in essence this should basically run once every Publish cycle, and if you make it happen as soon as the new major version has been Approved, then it should be good. By using an 'Upon Change' WF, it will then try and run a second time but of course should pause. And because there is an instance of the WF already running (albeit in a paused state), even though you change the document a number of times, you can only have one WF of a type running at a time, and there it is just going to wait until the time is correct and then finish.

I hope the above works for you. Regards

  • I understand the theory of what you're saying. However I am not sure where to begin in implementing that, specifically on putting a workflow on a document. Any extra information you could give me would much appreciated. Thanks – Sean Oct 20 '14 at 7:47
  • Sean - I'm not certain if me just editing my answer will kick off an email to you. So though adding a comment might do as well. Regards Alan C. – Merley72 Oct 20 '14 at 11:09
  • Thanks for the write up, I'll give it a go hopefully some point today, but if not today then tomorrow. I'll let you know how I get on. Thanks – Sean Oct 20 '14 at 12:37
  • Hi, I'm making an effort at this and I understand the structure of it all, but I'm not having much luck at creating it within a workflow. I don't suppose you have a screenshot of the workflow you've used in SPD for your application or something along those lines for further guidance? Thanks – Sean Oct 23 '14 at 12:40
  • Sean, I've not forgotten you, but have a lot on today. I'll prepare something later and get screenshots etc. Sorry to be a pain. Alan C. – Merley72 Oct 24 '14 at 13:43
1

You can filter the documents in library by Version in view.

I mean to say, this can be achieve to somewhat not fully by setting Version field in document library in Filter section like:

  1. Version >1.0
  2. Version <2.0

This show minor version between Major version 1.0 and Major version 2.0


One possible way is to add filter in library view as:

  • Version contains .0

Since Major version (published) are always in whole numbers and contain .0 at the end of it.

While Minor version always have .1 to .9 after whole number.

So, create two view:

  • In one view set filter, Version contain .0 (show only Major version)
  • In another view set filter, Version does not contain .0 which show you only minor version of documents.

NOTE:- once document is published its previous version can be seen in version history. Document library always show items with latest version.

  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Waqas Sarwar MVP Oct 17 '14 at 11:24
  • Can you please add more details about how to do that, to make this a complete answer – Robert Lindgren Oct 17 '14 at 11:31
  • @Waqas will take care next time for that! – ateet Oct 17 '14 at 11:46
  • I don't think I fully understand. Would that example only work for showing specific major versions. I want the view to show literally all major versions (even when there are associated minor versions). – Sean Oct 17 '14 at 11:56
  • No, that will only show document having minor version between 1.0 and 2.0 – ateet Oct 17 '14 at 11:57
1

In O365, there is no possibility to select Version 'does not contain'.

So, here is another solution.

In your Document Library, create a new Calculated column Minor Version with this formula:

=IF(RIGHT(Version,FIND(".",Version))=".0","Major","Minor")

Then create a new view Minor Version with this filter:

Show items only when the following is true:

Minor Version contains Minor

Regards,

0

Merley72's answer (Alan C) is very helpful and I've used it as a starting point. As this is SP2013, my approach is a bit different. I think there's not much point changing the document library schema by adding a new URL column and messing around with workflows. I would simply use client side rendering on a list view to change what the list view displays. It can go in a Script Editor web part on the page. This solution is currently a bit naive because it does not handle links to open in the browser, but I'm still working on it. One thing I'm trying to work out is how to get the correct Modified and ModifiedBy stamps for the last major version:

<script type="text/javascript">
(function() {
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
        ListTemplateType: 101,
        Templates: {
            OnPreRender: function(ctx) {
                for (var i = ctx.ListData.Row.length - 1; i > -1; i--) {
                    var row = ctx.ListData.Row[i];
                    var versionString = row._UIVersionString;
                    var versionFloat = parseFloat(versionString);
                    if (versionFloat < 1.0) {
                        // this removes any rows that have had no published version yet
                        ctx.ListData.Row.splice(i, 1);
                        continue;
                    }

                    var versionInt = parseInt(versionFloat);
                    versionString = versionInt + '.0';
                    // The link doesn't work if there are no minor versions beyond this
                    if (versionString == row._UIVersionString) continue;

                    var versionBin = versionInt * 512;
                    row._UIVersionString = versionString;
                    row.FileRef = '/_vti_history/' + versionBin + row.FileRef;
                }
            }
        }
    });
})();
</script>

I'd by very interested to hear whether anyone has any ideas about the time stamps and modifier.

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.