{"id":1452,"date":"2022-08-30T15:16:39","date_gmt":"2022-08-30T15:16:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/19\/getting-a-hyperlink-field-column-to-display-data-as-a-hyperlink-from-a-sharepoint-list-using-javascript-and-jquery-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:39","modified_gmt":"2022-08-30T15:16:39","slug":"getting-a-hyperlink-field-column-to-display-data-as-a-hyperlink-from-a-sharepoint-list-using-javascript-and-jquery-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/getting-a-hyperlink-field-column-to-display-data-as-a-hyperlink-from-a-sharepoint-list-using-javascript-and-jquery-collection-of-common-programming-errors\/","title":{"rendered":"Getting a hyperlink field\/column to display data as a hyperlink from a SharePoint List, using JavaScript and jQuery-Collection of common programming errors"},"content":{"rendered":"<p>I have what I think should be a simple issue to resolve, but it has taken me way too long to figure out.<\/p>\n<p>The background on this is thus: basically what I have is a SharePoint List that contains task items. We have created a .js file and published it to the Site Assets section along with some jQuery files. These files serve to pull data from that task list and use it in a new task list (for testing) using a CAML query.<\/p>\n<p>Basically, what all this does is: using a webpart, allow us in a test segment of the SP site to take that test task list and re-sort it using drag and drop (we select any row and drag it to where we want it to be in the list and it drops right there).<\/p>\n<p>So with all that, my actual problem is very simple. On this drag and drop list, one of the columns is an Edit column. It pulls a hyperlink field from the source task list. In my test list, I cannot for the life of me get that link to display as a hyperlink, it will only display as text! I am pretty new to integrating all this JavaScript, SharePoint, jQuery, etc so am probably missing something obvious. I would be very grateful for any assistance and thank you in advance. Here is the code I am using, followed by a little more explanation. Everything works, except the link!<\/p>\n<p><strong>Here is the CAML query, looking at the data from the list:<\/strong><\/p>\n<pre><code>function loadPrioritizedList() {\n    $(\"#tasksUL\").empty();\n\/\/ TDs below have to be 3 more width than the headers \n    $().SPServices({\n        operation: \"GetListItems\",    \n        webURL: myURL,\n        listName: targetListName,\n        CAMLViewFields: \"\",\n        CAMLQuery: '' +\n        '' +\n        '' +\n        '' +\n        '', \n        CAMLRowLimit: listrowlimit,  \n<\/code><\/pre>\n<p><strong>And here is where I am using the data:<\/strong><\/p>\n<pre><code>     CAMLRowLimit: listrowlimit,  \n            completefunc: function (xData, Status) {\n                $(xData.responseXML).SPFilterNode(\"z:row\").each(function() {\n                    var tdHtml = \"<\/code><\/pre>\n<tr class='sortable_row' id=\"+ $(this).attr(\">\n<td style=\"\\&quot;width:40px;\\&quot;\"><code>\" + PriorityFormat($(this).attr(\"ows_Priority_x0020_Number\")); + \"<\/code><\/td>\n<td style=\"\\&quot;width:40px;\\&quot;\">&#8221; + ($(this).attr(&#8220;ows_Edit_x0020_Link&#8221;)).split(&#8220;, &#8220;)[1] + &#8220;<\/td>\n<td style=\"\\&quot;width:46px;\\&quot;\">&#8221; + $(this).attr(&#8220;ows_Priority&#8221;) + &#8220;<\/td>\n<td style=\"\\&quot;width:40px;\\&quot;\">&#8221; + TopItem($(this).attr(&#8220;ows_Top_x0020_Item_x003f_&#8221;)) + &#8220;<\/td>\n<td style=\"\\&quot;width:300px;\\&quot;\">&#8221; + StringChk($(this).attr(&#8220;ows_Purpose&#8221;)) + &#8220;<\/td>\n<td style=\"\\&quot;width:125px;\\&quot;\">&#8221; + StringChk($(this).attr(&#8220;ows_Work_x002d_Task_x0020_Order&#8221;)) + &#8220;<\/td>\n<td style=\"\\&quot;width:150px;\\&quot;\">&#8221; + StringChk($(this).attr(&#8220;ows_Work_x0020_Status&#8221;)) + &#8220;<\/td>\n<td style=\"\\&quot;width:100px;\\&quot;\">&#8221; + FormatDate($(this).attr(&#8220;ows_DueDate&#8221;)) + &#8220;<\/td>\n<td style=\"\\&quot;width:75px;\\&quot;\">&#8221; + StringChk($(this).attr(&#8220;ows_Task_x0020_Type&#8221;)) + &#8220;<\/td>\n<\/tr>\n<p>&#8220;; $(&#8220;#tasksUL&#8221;).append(tdHtml);<\/p>\n<p><strong>The data element that needs to be a hyperlink is:<\/strong><\/p>\n<p>I was thinking I would have to format as a link here:<\/p>\n<pre><code>tdHtml = tdHtml + \"<\/code><\/pre>\n<td style=\"\\&quot;width:40px;\\&quot;\"><code>\" + ($(this).attr(\"ows_Edit_x0020_Link\")).split(\", \")[1] + \"<\/code><\/td>\n<p><code>\";<\/code><\/p>\n<p>The data from the source table is a URL, followed by &#8220;, Edit&#8221; which in the source displays &#8220;Edit&#8221; as the link &#8211; if a user clicks that link, it opens the row (task) item to be able to edit it. I am trying to replicate that here (hence the &#8220;.split&#8221;), but again, am only getting text back. Same thing happens if I split for the URL instead of &#8220;Edit&#8221;.<\/p>\n<p><strong>Here is the full code from the whole .js file:<\/strong><\/p>\n<pre><code>\n\n    #tasksUL {\n        PADDING-BOTTOM: 0px; LIST-STYLE-TYPE: none; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px\n    }\n    #tasksUL LI {\n        PADDING-BOTTOM: 0.4em; MARGIN: 0px 3px 3px; PADDING-LEFT: 1.5em; PADDING-RIGHT: 0.4em; HEIGHT: 10px; FONT-SIZE: 1.4em; CURSOR: pointer; PADDING-TOP: 0.4em\n    }\n    #tasksUL LI SPAN {\n        POSITION: absolute; MARGIN-LEFT: -1.3em\n    }\n    .listtable {\n        font-size:10px;\n        color:#333333;\n        border-width: 1px;\n        border-color: #729ea5;\n        border-collapse: collapse !important;\n        position: relative;\noverflow-y:auto;\nfloat:left !important; \n    }\n    .listtable_hdr th {\n        font-size:10px;\n        background-color:#acc8cc;\n        border-width: 1px;\n        padding: 4px;\n        border-style: solid;border-color: #729ea5;\n        text-align:left;\n    }\n    .listtable tr {\n        background-color:#d4e3e5;\n    }\n    .listtable td {\n        font-size:10px;\n        border-width: 1px;\n        padding: 4px;\n        border-style: solid;\n        border-color: #729ea5;\n        vertical-align:center;\nborder-collapse: collapse;\n    }\n    .listtable_hdr\n    {   \/* this div used as a fixed column header above the porfolio table, so we set bkgrnd color here *\/\n        position: static;    float: left;                        \n    }\n\n\n\n\n\n\n\n\n    \/\/CONFIGURATION VARIABLES\n    \/\/Assumes that this list is on the same site as the WebPart\n    var targetListName = \"AI Test List\";\n    var myURL = \"https:\/\/myteam.navair.navy.mil\/air\/68cbo\/Sandbox\"\n    var updatecount = 100;\n    var listrowlimit = 50;\n    var tablewidth = 975;\n\n    var fixHelperModified = function(e, tr) {\n\n        var $originals = tr.children();\n        var $helper = tr;\n\n        $helper.children().each(function(index) {\n            $(this).width($originals.eq(index).width())\n        });\n    $helper.width(tablewidth);\n\n        $helper.css('background-color', '#d3e324');\n\n        return $helper;\n    };\n\n    function PriorityFormat(item) {\n        if (typeof item === 'undefined')\n            return 0;\n        else\n            return parseInt(item);\n    }\n\n    function TopItem(item) {\n        if (item == \"1\")\n            return \"Yes\";\n        else \n            return \"No\";\n    }\n\n    function StringChk(item) {\n        if (typeof item === 'undefined')\n            return \" \";\n        else\n            return item;\n    }\n\n    function FormatDate(item) {\n        if (typeof item === 'undefined')\n            return \" \";\n        else {\n            var d = $.datepicker.parseDate(\"yy-mm-dd\",  item);\n            var dt_to = $.datepicker.formatDate('dd\/mm\/yy', d);\n            return dt_to;\n        }\n    }\n\n    function loadPrioritizedList() {\n        $(\"#tasksUL\").empty();\n    \/\/ TDs below have to be 3 more width than the headers \n        $().SPServices({\n            operation: \"GetListItems\",    \n            webURL: myURL,\n            listName: targetListName,\n            CAMLViewFields: \"\",\n            CAMLQuery: '' +\n            '' +\n            '' +\n            '' +\n            '', \n            CAMLRowLimit: listrowlimit,  \n            completefunc: function (xData, Status) {\n                $(xData.responseXML).SPFilterNode(\"z:row\").each(function() {\n                    var tdHtml = \"<\/code><\/pre>\n<tr class='sortable_row' id=\"+ $(this).attr(\">\n<td style=\"\\&quot;width:40px;\\&quot;\"><code>\" + PriorityFormat($(this).attr(\"ows_Priority_x0020_Number\")); + \"<\/code><\/td>\n<td style=\"\\&quot;width:40px;\\&quot;\">&#8221; + ($(this).attr(&#8220;ows_Edit_x0020_Link&#8221;)).split(&#8220;, &#8220;)[1] + &#8220;<\/td>\n<td style=\"\\&quot;width:46px;\\&quot;\">&#8221; + $(this).attr(&#8220;ows_Priority&#8221;) + &#8220;<\/td>\n<td style=\"\\&quot;width:40px;\\&quot;\">&#8221; + TopItem($(this).attr(&#8220;ows_Top_x0020_Item_x003f_&#8221;)) + &#8220;<\/td>\n<td style=\"\\&quot;width:300px;\\&quot;\">&#8221; + StringChk($(this).attr(&#8220;ows_Purpose&#8221;)) + &#8220;<\/td>\n<td style=\"\\&quot;width:125px;\\&quot;\">&#8221; + StringChk($(this).attr(&#8220;ows_Work_x002d_Task_x0020_Order&#8221;)) + &#8220;<\/td>\n<td style=\"\\&quot;width:150px;\\&quot;\">&#8221; + StringChk($(this).attr(&#8220;ows_Work_x0020_Status&#8221;)) + &#8220;<\/td>\n<td style=\"\\&quot;width:100px;\\&quot;\">&#8221; + FormatDate($(this).attr(&#8220;ows_DueDate&#8221;)) + &#8220;<\/td>\n<td style=\"\\&quot;width:75px;\\&quot;\">&#8221; + StringChk($(this).attr(&#8220;ows_Task_x0020_Type&#8221;)) + &#8220;<\/td>\n<\/tr>\n<p>&#8220;; $(&#8220;#tasksUL&#8221;).append(tdHtml); }); } }); $(&#8220;#tasksUL&#8221;).sortable({ containment: &#8220;#scroll2&#8221;, helper: fixHelperModified, scroll: true, axis: &#8220;y&#8221;, cursor: &#8220;move&#8221; }).disableSelection(); } \/\/Beginning to save items function saveListOrder() { $(&#8220;#Dialog&#8221;).dialog({ width: 200, height: 100, title: &#8220;Saving&#8230;&#8221;, resizable: false, closeOnEscape: false, modal: true }); alert(&#8216;Saving new list order.&#8217;); var total = 0; var itemcnt = 0; var msgstart = &#8220;&#8221;; var msgend = &#8220;&#8221;; var updatestart = &#8220;&#8221;; var updateend = &#8220;&#8221;; \/\/ process each var updatemsg = updatestart; $(&#8216;#tasksUL tr&#8217;).each(function(index) { \/\/ here we want to do &#8216;updatecount&#8217; at a time to the list itemcnt = itemcnt + 1; total = total + 1; \/\/ create the update method for this item updatemsg = updatemsg + msgstart; updatemsg = updatemsg + &#8220;&#8221; + total + &#8220;&#8221;; var itemId = $(this).attr(&#8220;id&#8221;); updatemsg = updatemsg + &#8220;&#8221; + itemId + &#8220;&#8221;; updatemsg = updatemsg + msgend; \/\/ if we hit 100 then save to list and reset counter if (itemcnt == 100) { itemcnt = 0; updatemsg = updatemsg + updateend; SaveItem(updatemsg, total); updatemsg = updatestart; } }); \/\/ Now we need to update the last items if (itemcnt &gt; 0) { updatemsg = updatemsg + updateend; SaveItem(updatemsg, total); } alert(&#8216;List items saved. Reloading list.&#8217;); $(&#8220;#saveid&#8221;).html(&#8220;&#8221;); loadPrioritizedList(); $(&#8220;#Dialog&#8221;).dialog(&#8216;close&#8217;); } function SaveItem(updatemsg, total) { $().SPServices({ operation: &#8220;UpdateListItems&#8221;, debug:false, async: false, batchCmd: &#8220;Update&#8221;, listName: targetListName, updates: updatemsg, completefunc: function(xData, Status) { $(&#8220;#saveid&#8221;).html(&#8220;Updated &#8221; + total + &#8221; list items&#8221;); } }); } $(document).ready(function() { \/\/alert(&#8220;jQuery&#8221;); \/\/alert($().SPServices.SPGetCurrentSite()); \/\/$(&#8216;.listtable&#8217;).css(&#8216;cursor&#8217;, &#8216;pointer&#8217;); $(&#8220;#Dialog&#8221;).dialog({ width: 200, height: 100, title: &#8220;Loading&#8230;&#8221;, resizable: false, closeOnEscape: false, modal: true }); $(&#8220;#msgid&#8221;).html(&#8220;Drag list items to save priority.&#8221;); loadPrioritizedList(); $(&#8220;#Dialog&#8221;).dialog(&#8216;close&#8217;); }); Drag rows to new position to change List Order.<br \/>\nSave List Order<\/p>\n<table width=\"975px\">\n<tr>\n<th class=\"contents_header\" style=\"width:37px;\">List Order<\/th>\n<th class=\"contents_header\" style=\"width:42px;\">Edit<\/th>\n<th class=\"contents_header\" style=\"width:42px;\">Priority<\/th>\n<th class=\"contents_header\" style=\"width:37px;\">Top Item?<\/th>\n<th class=\"contents_header\" style=\"width:297px;\">Effort\/Purpose<\/th>\n<th class=\"contents_header\" style=\"width:122px;\">Contract-Task Order<\/th>\n<th class=\"contents_header\" style=\"width:147px;\">Work Status<\/th>\n<th class=\"contents_header\" style=\"width:97px;\">Action Need Date<\/th>\n<th class=\"contents_header\" style=\"width:72px;\">Action Type<\/th>\n<\/tr>\n<\/table>\n<table width=\"975px\"><\/table>\n<p><img decoding=\"async\" src=\"..\/SiteAssets\/\/LoadingAnimationBlue.gif\" \/><\/p>\n<p>Thanks again for any help!<\/p>\n<ol>\n<li>\n<p>Not sure i understand the problem, but, Did you try this:<\/p>\n<pre><code>tdHtml = tdHtml + '<\/code><\/pre>\n<p>&#8216;;<\/p>\n<p>Khalil.<\/p>\n<table>\n<tr>\n<td style=\"\\&quot;width:40px;\\&quot;\">&#8216;+ ($(this).attr(&#8220;ows_Edit_x0020_Link&#8221;)).split(&#8220;, &#8220;)[1] +&#8217;<\/td>\n<\/tr>\n<\/table>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-19 13:17:21. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have what I think should be a simple issue to resolve, but it has taken me way too long to figure out. The background on this is thus: basically what I have is a SharePoint List that contains task items. We have created a .js file and published it to the Site Assets section [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1452","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1452"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1452\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}