{"id":964,"date":"2017-05-22T12:52:29","date_gmt":"2017-05-22T18:52:29","guid":{"rendered":"http:\/\/www.idubbs.com\/blog\/?p=964"},"modified":"2017-05-22T12:52:29","modified_gmt":"2017-05-22T18:52:29","slug":"js-link-creating-custom-links","status":"publish","type":"post","link":"https:\/\/www.idubbs.com\/blog\/2017\/js-link-creating-custom-links\/","title":{"rendered":"JS Link &ndash; Creating Custom Links"},"content":{"rendered":"<p>I\u2019ve spoken about this topic so many times I keep forgetting that I haven\u2019t put together a decent post on the subject even though I\u2019ve had sample code posted for quite some time (see References below). <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smilewithtongueout\" style=\"border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none\" alt=\"Smile with tongue out\" src=\"http:\/\/www.idubbs.com\/blog\/wp-content\/uploads\/2017\/05\/wlEmoticon-smilewithtongueout.png\"> In my opinion, after conditional formatting this is a sweet spot for JS Link use cases and functionally WAY more useful. <\/p>\n<p><strong><font color=\"#c0504d\">Disclaimer<\/font><\/strong>: For those of you using SharePoint 2013, this is still relevant content. If you are using SharePoint 2016 or O365 and have PowerApps available and\/or are only using \u2018modern\u2019 pages and views there are other potential solutions for you. <\/p>\n<p>Business-wise, what makes custom links useful is the ability for users to build solutions \u2013 \u2018stitching\u2019 together SharePoint functionality into productive business solutions \u2013 beyond what the out of box lists and libraries provide. <\/p>\n<p>What makes custom links with JS Link in SharePoint so useful is the crossing of a few core bits of functionality in SharePoint \u2013 that we\u2019ll cover in more detail in this article: <\/p>\n<ul>\n<li>Most everything in SharePoint is available via a URL \u2013 so we can \u2018decode\u2019 the links SharePoint uses to build our own links to the data we want our users to get to<\/li>\n<li>\u2018Source\u2019 data passed through the querystring allows us to control where the user is taken after a form is used (assuming the link destination was a form \u2013 it doesn\u2019t have to be)<\/li>\n<li>Creating a HTML link tag is super easy<\/li>\n<\/ul>\n<h3>User Experience Tweaking<\/h3>\n<p>You can use CSR to build \u2018web-user-friendly\u2019 vs. \u2018SharePoint-user-friendly\u2019 user interfaces. If all your users are familiar with SharePoint this isn\u2019t a compelling reason. However, for environments where non-office workers (warehouse, production, etc.) are using SharePoint sites and solutions, making the interface intuitive \u2013 making it more \u2018web-friendly\u2019 \u2013 is a compelling reason to look at enhancements like this. For example: <\/p>\n<p>Non-SharePoint users don\u2019t know what the ellipses (\u2026) are. They don\u2019t know they need to click on the \u2018\u2026\u2019 to get a menu for more details, etc. <br \/><a href=\"http:\/\/www.idubbs.com\/blog\/wp-content\/uploads\/2017\/05\/image-6.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/www.idubbs.com\/blog\/wp-content\/uploads\/2017\/05\/image_thumb-6.png\" width=\"244\" height=\"201\"><\/a><\/p>\n<p>By adding a column with web links to forms, it makes the interface easier to navigate \u2013 the useful links are displayed prominently instead of inside of a menu that needs to be opened first. If you had custom forms this same approach could be used to get the user to those forms instead of the default forms. SharePoint only enables linking to the default forms in the interface. <br \/><a href=\"http:\/\/www.idubbs.com\/blog\/wp-content\/uploads\/2017\/05\/image-7.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/www.idubbs.com\/blog\/wp-content\/uploads\/2017\/05\/image_thumb-7.png\" width=\"280\" height=\"94\"><\/a><\/p>\n<p>This also gives the solution owner more control over the interface by only displaying the controls they want made available to users. <\/p>\n<h3>How-To<\/h3>\n<p>If you use the SharePoint menu to navigate to the Edit page and look at the URL you will see something like this:  <\/p>\n<p><a title=\"https:\/\/forgegroup.sharepoint.com\/TeamSite\/CSR\/Lists\/DemoList\/EditForm.aspx?ID=1&amp;Source=https%3A%2F%2Fforgegroup%2Esharepoint%2Ecom%2FTeamsite%2FCSR%2FSitePages%2FDemo%2520-%2520Link%2520to%2520Pages%2520and%2520Forms%2Easpx&amp;ContentTypeId=0x01004578E7B0B3F1BE41A0EE6CF023F4518D\" href=\"https:\/\/forgegroup.sharepoint.com\/TeamSite\/CSR\/Lists\/DemoList\/EditForm.aspx?ID=1&amp;Source=https%3A%2F%2Fforgegroup%2Esharepoint%2Ecom%2FTeamsite%2FCSR%2FSitePages%2FDemo%2520-%2520Link%2520to%2520Pages%2520and%2520Forms%2Easpx&amp;ContentTypeId=0x01004578E7B0B3F1BE41A0EE6CF023F4518D\">https:\/\/forgegroup.sharepoint.com\/TeamSite\/CSR\/Lists\/DemoList\/EditForm.aspx?ID=1&amp;Source=https%3A%2F%2Fforgegroup%2Esharepoint%2Ecom%2FTeamsite%2FCSR%2FSitePages%2FDemo%2520-%2520Link%2520to%2520Pages%2520and%2520Forms%2Easpx&amp;ContentTypeId=0x01004578E7B0B3F1BE41A0EE6CF023F4518D<\/a><\/p>\n<p>If we break the URL down we get the following: <\/p>\n<ul>\n<li><a title=\"https:\/\/forgegroup.sharepoint.com\/TeamSite\/CSR\/Lists\/DemoList\/EditForm.aspx?ID=1&amp;Source=https%3A%2F%2Fforgegroup%2Esharepoint%2Ecom%2FTeamsite%2FCSR%2FSitePages%2FDemo%2520-%2520Link%2520to%2520Pages%2520and%2520Forms%2Easpx&amp;ContentTypeId=0x01004578E7B0B3F1BE41A0EE6CF023F4518D\" href=\"https:\/\/forgegroup.sharepoint.com\/TeamSite\/CSR\/Lists\/DemoList\/EditForm.aspx\">https:\/\/forgegroup.sharepoint.com\/TeamSite\/CSR\/Lists\/DemoList\/EditForm.aspx<\/a><br \/>This is the URL for the form page<\/li>\n<li>?ID=1<br \/>This is the parameter passed in that tells the form which item ID in the list to display<\/li>\n<li>&amp;Source=https%3A%2F%2Fforgegroup%2Esharepoint%2Ecom%2FTeamsite%2FCSR%2FSitePages%2FDemo%2520-%2520Link%2520to%2520Pages%2520and%2520Forms%2Easpx<br \/>This tells SharePoint where to navigate when the form is submitted or cancelled \u2013 essentially where the user ends up next. This can be VERY useful when building your own solution. <\/li>\n<li>&amp;ContentTypeId=0x01004578E7B0B3F1BE41A0EE6CF023F4518D<br \/>Finally, this is the content type for the item in the list. We aren\u2019t using this information for our example. <\/li>\n<\/ul>\n<p>What we\u2019re doing with the CSR code is creating our own link that will be displayed in an overridden column. The complete sample code can be found in the CSR_CustomLinks.js file. We\u2019ll just look at the key lines here:<\/p>\n<p><a href=\"http:\/\/www.idubbs.com\/blog\/wp-content\/uploads\/2017\/05\/image-8.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/www.idubbs.com\/blog\/wp-content\/uploads\/2017\/05\/image_thumb-8.png\" width=\"587\" height=\"94\"><\/a><\/p>\n<ul>\n<li>The link is going to \u2018..\/Lists\/DemoList\/EditForm.aspx\u2019 where \u2018DemoList\u2019 is the name of my list and \u2018EditForm.aspx\u2019 is the default edit form created for the list. If you\u2019ve created a new form (with SharePoint Designer, etc.) and want to use it, this is where you\u2019d put the name of the file. You could even leave the default \u2018edit\u2019 form as default but use this link to get to a separate edit form. <\/li>\n<li>\u2018ID\u2019 is the name of the parameter we\u2019re sending to the form. We\u2019re getting the data from the list as ctx.CurrentItem.ID <\/li>\n<li>Then comes our own \u2018Source\u2019 value to tell SharePoint where to navigate after the form has been used. This can be helpful if you want to direct users to a specific place other than where they came from. <\/li>\n<li>Finally, \u2018Edit\u2019 is the text that will displayed as the link. You can use whatever verbiage makes sense to your users here OR replace the text with a graphic or icon. <\/li>\n<\/ul>\n<p>In the sample code I\u2019m actually building two links \u2013 \u2018Edit\u2019 and \u2018Details\u2019 in the same column override. <\/p>\n<p>Get creative with this. The link doesn\u2019t have to be to a form for the current list. It could be a view for <em>another<\/em> list with a reference back to the current list. For example you might have a document library where you\u2019re keeping reference documents for a list and use a reference ID field in the document library to connect back to the current list. You could use this CSR approach to build the URL string to a view of the document library and filter it by the reference ID\u2026 Then a user could be looking at the current list and click on a simple link to all the related documents for that item. <\/p>\n<h3>Notes<\/h3>\n<ul>\n<li><strong>Using graphics:<\/strong> Choose a location for any graphics you want to use as part of your solution. A good place might be the SiteAssets library. Then use code that looks something like this: <br \/><a href=\"http:\/\/www.idubbs.com\/blog\/wp-content\/uploads\/2017\/05\/image-9.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"http:\/\/www.idubbs.com\/blog\/wp-content\/uploads\/2017\/05\/image_thumb-9.png\" width=\"507\" height=\"79\"><\/a><br \/>Replacing the \u2018Edit\u2019 text with an HTML image tag linking to your image file. <\/li>\n<li>Combine this link with <a href=\"http:\/\/www.idubbs.com\/blog\/2014\/js-link-csr-view-conditional-formatting\/\" target=\"_blank\">conditional formatting<\/a> and potentially display different actions or icons depending on the content of your list item. <\/li>\n<li><a href=\"http:\/\/www.idubbs.com\/blog\/2016\/jslink-filter-on-a-lookup-column-with-csr\/\" target=\"_blank\">Filtering on a lookup column<\/a> is another post using a similar custom link approach. <\/li>\n<li><strong>PowerApps:<\/strong> Moving forward solutions like described in this post will be accomplished using <a href=\"https:\/\/powerapps.microsoft.com\" target=\"_blank\">PowerApps<\/a>. If you\u2019re already using SharePoint Online, the capabilities are already available by building not only a list view from a SharePoint list, but being able to customize each column and build custom forms that you can link to within your PowerApp. <\/li>\n<\/ul>\n<h3>References<\/h3>\n<ul>\n<li><a href=\"http:\/\/www.idubbs.com\/blog\/2014\/js-link-hello-world\/\" target=\"_blank\">Hello World JS Link example<\/a> \u2013 If you\u2019ve never used the JS Link property of a web part, start here to understand the basics. <\/li>\n<li>Sample code \u2013 <a href=\"http:\/\/www.idubbs.com\/blog\/?attachment_id=624\" target=\"_blank\">CSR_CustomLinks.js<\/a> <\/li>\n<li><a href=\"http:\/\/www.idubbs.com\/blog\/js-link-and-csr\/\" target=\"_blank\">JS Link and CSR sample code, blog posts, and references<\/a><\/li>\n<li>Get or create your own icons \u2013 <a href=\"https:\/\/www.syncfusion.com\/downloads\/metrostudio\" target=\"_blank\">Syncfusion Metro Studio<\/a> <br \/>(Thanks Tamara Bredemus for that suggestion!) <\/li>\n<li><a href=\"http:\/\/www.idubbs.com\/blog\/powerapps-and-flows\/\" target=\"_blank\">PowerApps references and posts<\/a><\/li>\n<li>And just in case you\u2019re new to HTML as well, check out the <a href=\"https:\/\/www.w3schools.com\/html\/default.asp\" target=\"_blank\">w3schools tutorials and references<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve spoken about this topic so many times I keep forgetting that I haven\u2019t put together a decent post on the subject even though I\u2019ve had sample code posted for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[4,10,11,13,14,21],"tags":[52,129,79,130],"class_list":["post-964","post","type-post","status-publish","format-standard","hentry","category-js-link","category-office365","category-sharepoint","category-sharepoint-2013","category-sharepoint-2016","category-sharepoint-online","tag-csr","tag-links","tag-sharepoint-designer","tag-source"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pgWQ1-fy","jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.idubbs.com\/blog\/wp-json\/wp\/v2\/posts\/964","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.idubbs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.idubbs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.idubbs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.idubbs.com\/blog\/wp-json\/wp\/v2\/comments?post=964"}],"version-history":[{"count":1,"href":"https:\/\/www.idubbs.com\/blog\/wp-json\/wp\/v2\/posts\/964\/revisions"}],"predecessor-version":[{"id":965,"href":"https:\/\/www.idubbs.com\/blog\/wp-json\/wp\/v2\/posts\/964\/revisions\/965"}],"wp:attachment":[{"href":"https:\/\/www.idubbs.com\/blog\/wp-json\/wp\/v2\/media?parent=964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.idubbs.com\/blog\/wp-json\/wp\/v2\/categories?post=964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.idubbs.com\/blog\/wp-json\/wp\/v2\/tags?post=964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}