1

I have a sharepoint 2010 list where I use the following script to directly open a list attachment when clicking on the Title.

<script src="/sitespace/sitename/subsitename/Scripts/jquery-1.11.2.min.js" type="text/javascript"></script><script>

var EnrichList = window.EnrichList || {};
EnrichList.UI = function () {

    function GetSiteUrl() {
        var siteUrl = window.location.href.substr(0, window.location.href.indexOf("/Default.aspx"));
        if (siteUrl.length == 0) {
            siteUrl = window.location.href.substr(0, window.location.href.indexOf("/SitePages"));
        }
        if (siteUrl.length == 0) {
            siteUrl = window.location.href.substr(0, window.location.href.indexOf("/Pages"));
        }
        if (siteUrl.length == 0) {
            siteUrl = window.location.href.substr(0, window.location.href.indexOf("/Lists"));
        }
        return siteUrl;
    }

    function OverloadEditLink() {
        EditLink2 = function(target,nr) {

            var href = $(target).attr('href');
            var idStart = href.substr(href.indexOf("&ID=") + 4);
            var id = idStart.substr(0, idStart.indexOf("&"));

            var siteUrl = GetSiteUrl();
            if (siteUrl.length > 0) {
                var getAttachmentsUrl = siteUrl + "/_vti_bin/ListData.svc/Content_New_2(" + id + ")?$expand=Attachments&$select=Id,Attachments";

                $.getJSON(getAttachmentsUrl, function (data) {
                   if (data.d.Attachments != null && data.d.Attachments.results != null && data.d.Attachments.results.length > 0) {
                       for (var i = 0; i < data.d.Attachments.results.length; i++) {
                          var attachmentsUrl = siteUrl + "/Lists/Content_New_2/Attachments/" + data.d.Id + "/" + data.d.Attachments.results[i].Name;
/*
For some files, open in Office Web Applications results in error "Service not available". 
To prevent that the user then will not be able to view the document, configure the web-address of native document as source --> it will then open in native client.
*/
                          var fileName = data.d.Attachments.results[i].Name.toLowerCase();
                          if (fileName.endsWith(".docx") || fileName.endsWith(".doc")) {
                              attachmentsUrl = siteUrl + "/_layouts/WordViewer.aspx?id=" + encodeURI(attachmentsUrl) + "&Source=" + encodeURI(attachmentsUrl) + "&DefaultItemOpen=1";
                          } else if (fileName.endsWith(".xlsx") || fileName.endsWith(".xls")) {
                              attachmentsUrl = siteUrl + "/_layouts/xlviewer.aspx?id=" + encodeURI(attachmentsUrl) + "&Source=" + encodeURI(attachmentsUrl) + "&DefaultItemOpen=1";
                          } else if (fileName.endsWith(".pptx") || fileName.endsWith(".ppt") || fileName.endsWith(".ppm")) {
                              attachmentsUrl = siteUrl + "/_layouts/PowerPoint.aspx?PowerPointView=ReadingView&PresentationId=" + encodeURI(attachmentsUrl) + "&Source=" + encodeURI(attachmentsUrl) + "&DefaultItemOpen=1";
                          }

                          window.open(attachmentsUrl, '_blank');
                       }
                   } 
                });
            }

        };
    }
    var ModuleInit = (function() {
        ExecuteOrDelayUntilScriptLoaded(OverloadEditLink, "inplview.js");
    })();

}();</script>

This works fine but I also have a column that concatenates 2 other columns. (One is the title field (text field) and the other is a drop down list.) I added LinkToItem="TRUE"/> to the concatenated column via SharePoint Designer. The values are now hyperlinks (to the item?) but they don't do anything at all.

Where I need some help is at getting the above mentioned functionality (one-click-open) on the value that is displayed in the concatenated column instead of the Title column.

Hope someone can help me out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.