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

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

share|improve this question
1  
Why not just use the built in Document ID functionality? It does all you want –  Robert Lindgren Aug 1 '13 at 18:38
    
The reason for this is that I am actually using multiple libraries, so the standard IDs would not be unique. –  Daniel Peters Jul 17 at 17:52
    
Sure it would, if you used different prefixes for the different libraries –  Robert Lindgren Jul 19 at 14:48
add comment

2 Answers 2

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";
share|improve this answer
add comment

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..."

share|improve this answer
add comment

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.