{"id":1450,"date":"2022-08-30T15:16:38","date_gmt":"2022-08-30T15:16:38","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/19\/generating-a-hyperlink-from-variables-or-other-method-using-javascript-jquery-and-caml-for-a-sharepoint-list-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:38","modified_gmt":"2022-08-30T15:16:38","slug":"generating-a-hyperlink-from-variables-or-other-method-using-javascript-jquery-and-caml-for-a-sharepoint-list-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/generating-a-hyperlink-from-variables-or-other-method-using-javascript-jquery-and-caml-for-a-sharepoint-list-collection-of-common-programming-errors\/","title":{"rendered":"Generating a hyperlink from variables or other method (using JavaScript, jQuery, and CAML for a SharePoint List)-Collection of common programming errors"},"content":{"rendered":"<p>This is a question on how to get a hyperlink into a SharePoint table where the hyperlink has to be generated from variables containing certain parts of the link (unless there is a different or better way). My apologies if I am asking my question in an unclear or improper fashion &#8211; I am quite new to this type of integration and some of these technologies. I may have included a lot more detail than necessary.<\/p>\n<p><strong>What I am doing:<\/strong><\/p>\n<p>Basically what I have is a SharePoint List that contains task items (called Task Test List). This is is published to a section of the site whose link looks like this:<\/p>\n<p>https:\/\/myteam.thiscompany.com\/techdev\/sandbox\/lists\/Task%20Test%20List\/Task%20List2.aspx<\/p>\n<p>We have created a .js file and published it to the Site Assets section. This JavaScript file also uses jQuery and a CAML query. What it does is pulls data from the Test Task List and uses it in a new task list (for testing) called SortList. This new list lives in a section called WebPart pages. The link for this site looks like this:<\/p>\n<p>https:\/\/myteam.thiscompany.com\/techdev\/sandbox\/WebPart%20Pages\/Forms\/AllItems.aspx<\/p>\n<p>The link for the actual page (called SortList) looks like this:<\/p>\n<p>https:\/\/myteam.thiscompany.com\/techdev\/Sandbox\/WebPart%20Pages\/SortList.aspx<\/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><strong>The problem:<\/strong> On this drag and drop list (SortList), one of the columns is an Edit column. It pulls a hyperlink field from the source task list. Clicking the link allows us to edit the task item (whose data makes up the row) &#8211; it does this by using the task ID.<\/p>\n<p>However that link, when clicked, is going to the webparts page, and I need it to go to the Test Task List. So for example, it goes here on click:<\/p>\n<p>https:\/\/myteam.thiscompany.com\/techdev\/Sandbox\/WebPart%20Pages\/Edit<\/p>\n<p>But I need it to go here:<\/p>\n<p>https:\/\/myteam.thiscompany.com\/techdev\/Sandbox\/Lists\/AI%20Test%20List\/Task\/editifs.aspx?List=532ed23b%2D1041%2D4600%2D887f%2D58b08e1f4b9d&#038;ID=1909&#038;Source=https%3A%2F%2Fmyteam%2Ethiscompany%2com%2FSandbox%2FLists%2FTask%2520Test%2520List%2FTask%2520List2%2Easpx&#038;Web=ba8a673c%2D8072%2D4a44%2Db895%2D4e1c1f962b2f<\/p>\n<p>All of this from the above link is what I think I need to change:<\/p>\n<p>List=532ed23b%2D1041%2D4600%2D887f%2D58b08e1f4b9d&amp;ID=1909&amp;Source=https%3A%2F%2Fmyteam%2Ethiscompany%2com%2FSandbox%2FLists%2FTask%2520Test%2520List%2FTask%2520List2%2Easpx&amp;Web=ba8a673c%2D8072%2D4a44%2Db895%2D4e1c1f962b2f<\/p>\n<p>In my current URL I am pointing to &#8220;Task%20List&#8221; and the correct name should be: &#8220;Task%20Test%List&#8221;.<\/p>\n<p>The GUID to use for the List is &#8220;532ed23b%2D1041%2D4600%2D887f%2D58b08e1f4b9d&#8221;<\/p>\n<p>As far as I can tell, the important parameters are the list= (which will need to be hardcoded so I was thinking to add a list variable in the JS file and reference that) and the ID= (which I already have).<\/p>\n<p>If that is correct, I am looking for advice on how to do that because I don&#8217;t know. Or if there are other methods I would be grateful to know them.<\/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 code for the link is currently:<\/strong><\/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><strong>Here is what the SortList looks like:<\/strong> <img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/39Drw.png\" \/><\/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 = \"Task Test List\";\n    var myURL = \"https:\/\/myteam.thiscompany.com\/techdev\/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;\">&#8216;+ ($(this).attr(&#8220;ows_Edit_x0020_Link&#8221;)).split(&#8220;, &#8220;)[1] +&#8217;<\/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>Actually you have to use <code>$(this).attr('ows_Edit_x0020_Link').split(', ')[0]<\/code> (note the [0] instead of [1]) for the &#8220;href&#8221;. If you use [1] then you&#8217;ll have &#8220;Edit&#8221; and not the URL<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-19 13:17:11. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>This is a question on how to get a hyperlink into a SharePoint table where the hyperlink has to be generated from variables containing certain parts of the link (unless there is a different or better way). My apologies if I am asking my question in an unclear or improper fashion &#8211; I am quite [&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-1450","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1450","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=1450"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1450\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}