0

After deploying a JSLink file to add a button to a list view, I'm getting the following error when expecting the page in Chrome developer tools. enter image description here

using the following to reference the item

~sitecollection/Site Assets/JSLinkAddCommentToManagerButton.js

here is the code:

(function () {
document.write('<style type="text/css">.btn {  background: #0072C6; 
background-image: -webkit-linear-gradient(top, #0072C6, #2980b9);   
background-image: -moz-linear-gradient(top, #0072C6, #2980b9);  background-
image: -ms-linear-gradient(top, #0072C6, #2980b9);  background-image: -o-
linear-gradient(top, #0072C6, #2980b9);  background-image: linear-  
gradient(to bottom, #0072C6, #2980b9);  font-family: Arial;  color: #ffffff;  font-size: 12px;  background: #0072C6;  padding: 6px 10px 6px 10px;  text-decoration: none; margin-right:10px;}<\/style>');
var statusFieldCtx = {};

statusFieldCtx.Templates = {};
statusFieldCtx.Templates.Fields = {
"Action": {
    "View": ShowButton
    }};

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(statusFieldCtx);
})();


function ShowButton(ctx) {

var _ItemId = ctx.CurrentItem.ID;
var TitleFeedback  = "Send Comment to Manager";

var TaskView = "/teams/MTS/Engagement/Lists/ShoutWall/DispForm.aspx?ID="+_ItemId;

return "<a href='javascript:void(0)' onclick=\"openViewDialog('" + TaskView    + "', '" + TitleFeedback  + "')\" class='btn'>Add Comment</a>";
}

function openViewDialog(tUrl, tTitle) {
       var options = {
         url: tUrl,
         title: tTitle,
         height:600,
         width:800,
         dialogReturnValueCallback: function(dialogResult) 
         { 
              SP.UI.ModalDialog.RefreshPage(dialogResult) 
         }

 };
   SP.UI.ModalDialog.showModalDialog(options);
 }
  • Have you uploaded this JS file to Site Assets library in your site collection and Are you able to access this JS file using the link shown in chrome console? – SlackerAmit Apr 27 '16 at 22:27
  • moving the file to the Style Library solved the issue – Jason Apr 28 '16 at 1:05
  • For easy CSR development see the Cisar Chrome Extension: chrome.google.com/webstore/detail/cisar/… – Danny '365CSI' Engelman Apr 30 '16 at 10:18
2

Your issue is that your URL is incorrect. There is no space in SiteAssets. The correct URL might be:

~sitecollection/SiteAssets/JSLinkAddCommentToManagerButton.js

Plus, I personally prefer using ~site rather than ~sitecollection as it makes clear that anything being referred is inside the current web.

In any event while getting the URL you should always read it from the document's ECB menu, to avoid any mistakes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.