1

As the title says, my code for the JSLink is not working on my list for non admins. I made sure that the script was published as a major version and it is still not working. My code is:

(function () {
console.log("Started");
var overrideCtx = {};
overrideCtx.Templates = {};

overrideCtx.Templates.Fields = {
    'Title': { 'View': updateName}
};

function updateName(ctx) {
    console.log(ctx.CurrentItem);
    var base_url = "https://blah.sharepoint.com";
    var file_path;

    if (ctx.CurrentItem.File_x0020_Type === "pdf") {
        file_path = base_url + ctx.CurrentItem.FileRef;
    }
    else {
        file_path = ctx.CurrentItem.ServerRedirectedEmbedUrl;
    }

    var title;

    if (ctx.CurrentItem.Title === "") {
        title = ctx.CurrentItem.FileLeafRef;
    }
    else {
        title = ctx.CurrentItem.Title;
    }

    return "<a href='" + file_path + "' style='color:#000000;'> " + title  + "</a>";
}

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);

})();

One odd thing I noticed is that if I refresh the page with the developer console open (IE 9), then the JSLink works. Any suggestions?

Thanks!

  • Is there any approval required, you said it was published as a major version. Is your site using minimal download strategy? – Eric Alexander Mar 31 '15 at 20:52
  • @PirateEric No approval required. I just double checked and minimal download strategy is not active for the site. There shouldn't be a permission issue is there? – bmartin Mar 31 '15 at 20:56
3

If you are using IE9 or lower the issue is probably your console.log. It's only exposed if you open your developer tools (F12). So what's happening is that your javascript fails at the first line if you haven't loaded the console object.

So either remove the console.log or do something like this:

console && console.log("Started");

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.