1

Here is the situation:

I have two libraries, one housing current documents, and another which serves as an archive. I have a workflow which sends the owner a link to their document.

The problem is that when the document is archived, the link is broken.

Here is my idea:

I created a list with two columns: Document ID and URL. Each document will have a unique Document ID and when it is archived, the URL will change to reflect it's new location.

I would like to issue links in an email which will redirect to the document's current location by refferencing the list. The links could be like "/SITE/pages/Links?DocID=123" where the page has a query string to determine which line in the list to reference. The page would then find that list item, and then redirect to the proper URL.

My Question(s):

Is this possible to do using javascript on the page? Is there a better way to accomplish the same functionality?

Thanks in advance for any help you can provide!

Daniel

3
  • 1
    Why not just use the built in Document ID functionality? It does all you want Aug 1, 2013 at 18:38
  • The reason for this is that I am actually using multiple libraries, so the standard IDs would not be unique. Jul 17, 2014 at 17:52
  • Sure it would, if you used different prefixes for the different libraries Jul 19, 2014 at 14:48

2 Answers 2

1

It is possible to implement with JavaScript.

There is very useful JavaScript library, called SPServices. You can use GetListItems method to execute CAML query with parameters you need to your document library, then build redirection string and redirect user to another location with following commands:

window.navigate("http://redirectaddress");

or

window.location = "http://redirectaddress";
0

I would recommend creating an Application Page that would forward the user to the url of the Document ID requested. But, you need Visual Studio and the ability to deploy farm solutions and sometimes a lighter approach works just as well.

You could do it with javascript. You would have to use a web part page or wiki page and add a Content Editor Web Part to the page, which is described here. Then, you could use the javascript client object model to get the field values, and you would end up with something to the effect of:

<script>

var documentInfoItems;

  ExecuteOrDelayUntilScriptLoaded(function() {
    var docId = getParameterByName("DocID");
    if (docId) {
      var ctx = new SP.ClientContext.get_current();
      var lst = ctx.get_web().get_lists().getByTitle('DocumentLookupList');
      var camlQuery = new SP.CamlQuery();
      camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name=\'Document_x0020_ID\'/>" + 
        "<Value Type=\'Number\'>" + 
        docId + 
        "</Value></Eq></Where></Query><RowLimit>1</RowLimit></View>");
      documentInfoItems = lst.getItems(camlQuery);
      ctx.load(documentInfoItems);
      ctx.executeQueryAsync(Function.createDelegate(this, this.GetDocumentInfoSucceeded), 
        Function.createDelegate(this, this.GetDocumentInfoFailed));        
    }
  }, "sp.js")

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

function GetDocumentInfoSucceeded(sender, args) {
  var listItemEnumerator = documentInfoItems.getEnumerator();
  if (listItemEnumerator.moveNext()) {
    window.location.replace(listItemEnumerator.get_current().get_item("URL"));
  } else {
    alert("Unable to find document with id " + getParameterByName("DocID"));
  }
}

function GetDocumentInfoFailed(sender, args) {
  alert("Unable to get document info");
}</script>

Since you would be using a page in SharePoint, you could then just add some text like "Loading your document, please wait..."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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