0

Some trick request came. We had list with columns as "Title", "Owner", "Description", "External Path", "Requester". In "title" column, we have given name of item, under "Description" some matter given and "external path" column, we have given some URL.

Now our request is when we click on "Title" column, it need to open "External path" column link. Hope someone got my point. Is it possible achieve my request?

enter image description here

4
  • Maybe you can create a calculated column with structure something like : <a href="[External Path]" target="_blank">[Title]</a> Apr 25, 2019 at 2:49
  • By keeping both fields mandatory and returning calculated field as number so that hyperlink will get created. Apr 25, 2019 at 2:50
  • Thanks mate, calculated column options not working. Apr 25, 2019 at 3:09
  • What is the exact problem? are you getting any error? Apr 25, 2019 at 5:51

2 Answers 2

1

If the "External Path" field is a single text field, we can add the following code into a script editor in list view page to achieve it.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
(function () { 
    // Create object that have the context information about the field that we want to change it's output render  
    var fieldContext = {}; 
    fieldContext.Templates = {}; 
    fieldContext.Templates.Fields = { 
        // Apply the new rendering for Available field on List View 
        "LinkTitle": { "View": fieldTemplate } 
    }; 
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(fieldContext);
})(); 

// This function provides the rendering logic for list view 
function fieldTemplate(ctx) { 
    var title = ctx.CurrentItem["Title"];     
    var externalPath = ctx.CurrentItem["External_x0020_Path"];  
    return "<a href='"+$(externalPath).text()+"' target='_blank'>"+title+"</a>"
}
</script>

enter image description here

If the "External Path" field is a multiple line of text field, and not in the list view. We can use the code below to achieve it.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
    $("div[field='LinkTitle']>a").attr("href","#");
    $("div[field='LinkTitle']>a").removeAttr("onclick");
    $("div[field='LinkTitle']>a").click(function(){
        var listGUID=$(".ms-listviewtable").attr("id").split("}-")[0].split("{")[1];
        var itemId=$(this).parent().attr("id");
        OpenExternalPath(listGUID,itemId);
    });
});
function OpenExternalPath(listGUID,itemId){
    $.ajax({
        url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists(guid'"+listGUID+"')/items("+itemId+")",
        type: "GET",
        headers: {
            "Accept": "application/json;odata=verbose",
        },
        success: function (data) {
            var externalPath=data.d.External_x0020_Path;
            if($(externalPath).text()!=""){
                window.open($(externalPath).text(), '_blank');
            }           
        },
        error: function (data) {
            //alert("Error");
        }
    });
}
</script>
7
  • thanks, mate, i tried your code but its not working for me. its showing "<script src="code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script> " on the script editor webpart Apr 25, 2019 at 2:46
  • its working, if we have two columns as "test" and "External Path". But in my case 8 column are present. its not working if we have more columns. Please suggest me for more columns. Apr 25, 2019 at 3:03
  • I suggest you provide the name and field type of all the columns for further research.
    – LZ_MSFT
    Apr 25, 2019 at 6:28
  • we have 15 columns in a list, 1 image with "hyperlink or picture" type column, 2 Title with "single line text", 3 Description with "Multiple lines of text", 4 Owner with "Person or group", 5 Condition with "single line text", 6 Status with "Choice" type, 7 Process with "Choice" type,8 external path with "Multiple lines of text", 9 internal path with "Multiple lines of text", 10 Condition with "single line text", 11Data with "multiple line of text", 12 Control with "Multiple line of text", 13 date with "date and time" 14 number with "single line text", 15 request with hyperlink. Apr 25, 2019 at 6:59
  • The "External Path" is multiple line of text? Do you want to store multiple link in this field? Example, if you have two links, which one do you want to open when click the "Title" column?
    – LZ_MSFT
    Apr 25, 2019 at 8:10
0

You could just create a "Hyperlink" column and hide the title column on the form and list view.

enter image description here

enter image description here

Or you can use jquery to get the href and replace your title columns href. enter image description here

<script src="/...../SiteAssets/jquery/jquery-1.8.3.min.js"></script>
<script>
$( document ).ready(function() {

    $('.ms-listviewtable > tbody > tr > td > a').each(function() {
        var getLink = $(this).attr('href');
        console.log("TEST: " + getLink);
        $(this).parent().prev().prev().children().children().removeAttr("href").removeAttr("onclick").attr("href",getLink);
    });
});
</script>

This will just swap out the href for each row. Might need some cleaning up of the code, but it should do the trick. In my case the link column was located right next to the title column.

enter image description here

UPDATE I "Single Line of Text" column pretty much works the same way.

enter image description here

I've added a new column at the end and modified the code as follows.

<script src="/./SiteAssets/jquery/jquery-1.8.3.min.js"></script>
<script>
$( document ).ready(function() {

    $('.ms-listviewtable > tbody > tr > td:nth-child(8) > a').each(function() {
        var getLink = $(this).attr('href');
        console.log("TEST: " + getLink);
        $(this).parent().prev().prev().prev().prev().prev().prev().children().children().removeAttr("href").removeAttr("onclick").attr("href",getLink);
    });
});
</script>

Make sure to include the jquery-1.8.3.min.js file

11
  • No, We have so many Hyperlink column exist. when we click on "Title" column, it need to open "External path" column link. Apr 25, 2019 at 1:02
  • Got it. Please see my edits.
    – Jaitsujin
    Apr 25, 2019 at 1:59
  • thanks Jaitsujin, i tried your script. "External path" column is not hyperlinked column, its "single text field" column on my case. Moreover, my columns are not located side by side. i tried different possibilities but it not working, could you please suggest and guide with updated code. Apr 25, 2019 at 3:09
  • Yes, let me put something together real quick and I'll update my post.
    – Jaitsujin
    Apr 25, 2019 at 7:09
  • Please see my comments after UPDATE.
    – Jaitsujin
    Apr 25, 2019 at 7:36

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.