I created a sharepoint task list with the column "Priority" according to this guide: https://code.msdn.microsoft.com/office/Client-side-rendering-code-0a786cdd#content

Then I linked the JS, which I saved on m SharePoint under the "Miscellaneous" Part of the Web Part. Now, what the script is supposed to do, is to look for the column "priority" and replace the words "High" with a red png-picture, the words "normal" with a yellow png-picture etc...

However it seems like the JS is not working at all, because the list does not Change it appearence at all. I tried different approaches like, not replacing the words with Pictures and only changing their colours etc, however ist not working so far

Here is the full code:

(function () { 

    var priorityFiledContext = {}; 
    priorityFiledContext.Templates = {}; 
    priorityFiledContext.Templates.Fields = { 
        "Priority": { "View": priorityFiledTemplate } 
    }; 

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(priorityFiledContext); 

})(); 

function priorityFiledTemplate(ctx) { 

    var priority = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; 

    if(priority=="High") { 
        return "<img src='/sites/020014/Name/Biblio/AmpelRed.png'/>";
    }           
    else if(priority=="Normal") { 
        return "<img src='/sites/020014/Name/Biblio/AmpelAmber.png'/>";
    } 
    else if(priority=="Low") { 
        return "<img src='/sites/020014/Name/Biblio/AmpelGreen.png'/>";
    } 

} 

now I am wondering, maybe this part of the code:

var priority = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; 

is supposed to find the "priority" coloumn, but im not sure, how it works...

thanks in advance!

  • 1
    hello can you share the path how you are refereing in the Miscellaneous property and have tried placing alert in the script. – Sunil sahu Aug 10 at 9:51
  • There is nothing wrong with your code. May be your JS file is not loading properly. I would recommend to try the solution provided by @Sunilsahu. That should work... – Rohit Waghela Aug 10 at 17:38

think its with refering the JS file in JS link property. A simple /v.js link will not work. Either of the following SharePoint tokens should be used instead:

For js file stored in SiteCollection

~sitecollection/your file path.

like :-

~sitecollection/SiteAssets/jslink.js

And for js file stored in SubSite/Web

~site/SiteAssets/your file path.

like :-

~site/SiteAssets/jslink.js

For more tokens you may refer

Try to link your JS using a content editor webpart.

while in edit mode navigate to Insert -> Media and Content ->Content Eiditor then edit the Content Editor to pull the URL path of your saved .js file.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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