{"id":177,"date":"2015-02-26T18:19:11","date_gmt":"2015-02-26T18:19:11","guid":{"rendered":"https:\/\/itgroove.net\/bangimportant\/?p=177"},"modified":"2023-02-24T21:39:46","modified_gmt":"2023-02-24T21:39:46","slug":"jslink-working-with-urls-in-sharepoint-lists","status":"publish","type":"post","link":"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/","title":{"rendered":"JSLink Working with URLs in SharePoint Lists"},"content":{"rendered":"\n<p>About a month or so ago we were working on a client project with the requirement to create a mechanism for displaying links to URLs that were too long for hyperlink column in a SharePoint Links List (that column has a 255 character max).<\/p>\n\n\n\n<p>The solution was fairly straightforward. We used JSLink to create a version of the links list that instead used the \u201cmultiple lines of text\u201d column.<\/p>\n\n\n\n<p>The setup was simple enough:<\/p>\n\n\n\n<ol><li>Create a Display Text (single line of text) column that holds the text that will be shown to the user<\/li><li>Create a URL column (multiple lines of text) to hold the URL itself<\/li><li>Use JSLink to override the Display Text column and create a hyperlink:\n &lt;a href=\u201d[URL Column Value]\u201d&gt;[Display Text Column Value]&lt;\/a&gt;\n<\/li><\/ol>\n\n\n\n<p>Easy enough right?<\/p>\n\n\n\n<p>But then we hit a snag, and although it was fairly minor it did give us pause.<\/p>\n\n\n\n<p>Apparently in SharePoint anytime you have a value in a list that begins with the http:\/\/ or https:\/\/ prefix it gets rendered as a clickable hyperlink. In other words behind the scenes <a href=\"http:\/\/google.ca\">http:\/\/google.ca<\/a> becomes &lt;a href=\u201d<a href=\"http:\/\/google.ca\">http:\/\/google.ca<\/a>\u201d&gt;<a href=\"http:\/\/google.ca%3c\/a\">http:\/\/google.ca&lt;\/a<\/a>&gt;.<\/p>\n\n\n\n<p>That means that instead of a nice clean output from the JSLink as shown in step 3 above we were instead getting the \u201c&lt;a href=&#8230;\u201d output from the URL column nested inside the href=\u201d\u201d field of my hyperlink.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The solution:<\/h2>\n\n\n\n<p>A little bit of string manipulation inside the JSLink to purge out the unwanted &lt;a&gt; tag.<\/p>\n\n\n\n<p>When SharePoint renders the links as &lt;a&gt; tags it uses double quotation marks for the href value. Therefore we can simply do:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var hyperlink = [JSLink code to reference your hyperlink column];\nvar linkHref = hyperlink.split('\"')[1];<\/pre>\n\n\n\n<p>This splits the hyperlink at the double quotation mark and then returns the 2<sup>nd<\/sup> item in the array which is the URL we want. (Remember 1 is really 2 in an array because the first item is 0).<\/p>\n\n\n\n<p>Obviously add some basic validation to ensure the Hyperlink column really does contain an &lt;a&gt; tag before processing and VOIL\u00c0. Problem solved.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>About a month or so ago we were working on a client project with the requirement to create a mechanism for displaying links to URLs that were too long for hyperlink column in a SharePoint Links List (that column has a 255 character max). The solution was fairly straightforward. We used JSLink to create a &hellip; <a href=\"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/\"><\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[4,7],"tags":[12,13,14,16],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JSLink Working with URLs in SharePoint Lists - Archive<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JSLink Working with URLs in SharePoint Lists - Archive\" \/>\n<meta property=\"og:description\" content=\"About a month or so ago we were working on a client project with the requirement to create a mechanism for displaying links to URLs that were too long for hyperlink column in a SharePoint Links List (that column has a 255 character max). The solution was fairly straightforward. We used JSLink to create a &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/\" \/>\n<meta property=\"og:site_name\" content=\"Archive\" \/>\n<meta property=\"article:published_time\" content=\"2015-02-26T18:19:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-24T21:39:46+00:00\" \/>\n<meta name=\"author\" content=\"Colin Phillips (Alumni)\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Colin Phillips (Alumni)\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/\",\"url\":\"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/\",\"name\":\"JSLink Working with URLs in SharePoint Lists - Archive\",\"isPartOf\":{\"@id\":\"https:\/\/regroove.ca\/archive\/#website\"},\"datePublished\":\"2015-02-26T18:19:11+00:00\",\"dateModified\":\"2023-02-24T21:39:46+00:00\",\"author\":{\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b\"},\"breadcrumb\":{\"@id\":\"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog Archive\",\"item\":\"https:\/\/regroove.ca\/archive\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JSLink Working with URLs in SharePoint Lists\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/regroove.ca\/archive\/#website\",\"url\":\"https:\/\/regroove.ca\/archive\/\",\"name\":\"Archive\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/regroove.ca\/archive\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b\",\"name\":\"Colin Phillips (Alumni)\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g\",\"caption\":\"Colin Phillips (Alumni)\"},\"url\":\"https:\/\/regroove.ca\/archive\/author\/cphillips\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JSLink Working with URLs in SharePoint Lists - Archive","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/","og_locale":"en_US","og_type":"article","og_title":"JSLink Working with URLs in SharePoint Lists - Archive","og_description":"About a month or so ago we were working on a client project with the requirement to create a mechanism for displaying links to URLs that were too long for hyperlink column in a SharePoint Links List (that column has a 255 character max). The solution was fairly straightforward. We used JSLink to create a &hellip;","og_url":"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/","og_site_name":"Archive","article_published_time":"2015-02-26T18:19:11+00:00","article_modified_time":"2023-02-24T21:39:46+00:00","author":"Colin Phillips (Alumni)","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Colin Phillips (Alumni)","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/","url":"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/","name":"JSLink Working with URLs in SharePoint Lists - Archive","isPartOf":{"@id":"https:\/\/regroove.ca\/archive\/#website"},"datePublished":"2015-02-26T18:19:11+00:00","dateModified":"2023-02-24T21:39:46+00:00","author":{"@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b"},"breadcrumb":{"@id":"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/regroove.ca\/archive\/2015\/02\/26\/jslink-working-with-urls-in-sharepoint-lists\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Archive","item":"https:\/\/regroove.ca\/archive\/"},{"@type":"ListItem","position":2,"name":"JSLink Working with URLs in SharePoint Lists"}]},{"@type":"WebSite","@id":"https:\/\/regroove.ca\/archive\/#website","url":"https:\/\/regroove.ca\/archive\/","name":"Archive","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/regroove.ca\/archive\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b","name":"Colin Phillips (Alumni)","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g","caption":"Colin Phillips (Alumni)"},"url":"https:\/\/regroove.ca\/archive\/author\/cphillips\/"}]}},"_links":{"self":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/177"}],"collection":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/comments?post=177"}],"version-history":[{"count":1,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/177\/revisions"}],"predecessor-version":[{"id":1853,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/177\/revisions\/1853"}],"wp:attachment":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/media?parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/categories?post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/tags?post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}