2

Scenario: I would like to have a link per line item that takes the user directly to the version history for that item.

Possible Solutions: I was thinking of creating calculated column or a custom workflow all that I am not 100% sure will work.

Can anyone help me find a way to have direct link to version history per line item that is done automatically per link item without having to create the url manually?

2

You could do it with Client Side Rendering to instead of having to work with calculated columns or workflows.

Save this code to a new text document and save it with the name renderVersionUrl.js with the file extension .js

You will need to add a new column named Version (single line of text) to your list.

Upload it to your site collections Site Assets library and then apply it to your list web part using the JSLink property. (Add ~site/siteassets/renderVersionUrl.js).

This will render your column named "Version" to a hyperlink to the current items version history.

enter image description here

SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {

  function getBaseHtml(ctx) {
    return SPClientTemplates["_defaultTemplates"].Fields.default.all.all[ctx.CurrentFieldSchema.FieldType][ctx.BaseViewID](ctx);
  }

  function init() {

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides({

     Templates: {
          Fields: {
              "Version": {
                  View: function(ctx) {
                    var itemId = ctx.CurrentItem.ID;
                    var listId = ctx.listName;
                    var currSite = ctx.HttpRoot;
                    var versionUrl = "<a href='"+ currSite + "/_layouts/15/Versions.aspx?list=" + listId + "&ID=" + itemId + "'>Version History</a>"; // removed extra single quotes
                    return versionUrl;
                    }
                }
            }
        },
    });
  }

  RegisterModuleInit(SPClientTemplates.Utility.ReplaceUrlTokens("~siteCollection/SiteAssets/renderVersionUrl.js"), init);
  init();

});
3

The URL for the version history is:

/_layouts/Versions.aspx?list={GUID}&ID={itemid}

The workflow can build a string and update a column with the value. Remember if workflow will run on update item, it will create a new version so workflow on new item added might be better in terms of your requirement.

I think CSR might be a better way to achieve this rather than calculated field or workflow.

2

Since the link to the versions page needs the item id, you'd need to do it through workflow when the item is created. The link looks like this:

https:///_layouts/15/Versions.aspx?list={7330FBF0-8603-41F2-B623-54F08E4835B7}&ID=563

You can build that through workflow. Add a URL field to your list, called 'Version History' for example.

Build up a string variable in workflow that has both parts of the url - the link and the description. Make sure they are separated by a comma and a space:

[%Workflow Context:Current Site URL%]/_layouts/15/Versions.aspx?list={7330FBF0-8603-41F2-B623-54F08E4835B7}&ID=[%Current Item:ID%], Version History

I'm not sure if you can get the GUID in the workflow, you might need to hardcode that.

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.