May 22 2017 09:24 AM
I am trying to use JS link by uploading the js file to the style library and then going to task list, edit page, web part properties and miscellaneous-> paste the link to the js file.
However, i could see the execution taking place.
// List View – Priority Color Sample // Muawiyah Shannak , @MuShannak (function () { alert( "check jslink"); // Create object that have the context information about the field that we want to change it's output render var priorityFiledContext = {}; priorityFiledContext.Templates = {}; priorityFiledContext.Templates.Fields = { // Apply the new rendering for Priority field on List View "Priority": { "View": priorityFiledTemplate } }; SPClientTemplates.TemplateManager.RegisterTemplateOverrides(priorityFiledContext); })(); // This function provides the rendering logic for list view function priorityFiledTemplate(ctx) { var priority = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; // Return html element with appropriate color based on priority value switch (priority) { case "(1) High": return "<span style='color :#f00'>" + priority + "</span>"; break; case "(2) Normal": return "<span style='color :#ff6a00'>" + priority + "</span>"; break; case "(3) Low": return "<span style='color :#cab023'>" + priority + "</span>"; } }
May 23 2017 02:03 AM
How do you implement it? are you using a script editor on the page or..
May 23 2017 02:17 AM
Use the browser's developer tool to debug your script and ensure that the value of priority is what you expect.
Kind regards
John
May 23 2017 08:41 AM
at console level i can see url appended by ?ctag=<some code>
So, if the url is :
<tenant name>/jslinkfiles/prioritycolor.js
when i check the console, it displays 404 error and when i click on the url. it displays
<tenant name>/jslinkfiles/prioritycolor.js?ctag=0$$16.0.6511.1207
How do i avoid this ctag to appear.
Thanks
May 23 2017 08:51 AM
May 23 2017 05:28 PM
May 23 2017 10:15 PM
so it is working now or still not?
when i see this<tenant name>/jslinkfiles/prioritycolor.js?ctag=0$$16.0.6511.1207 you are missing the library where you are putting the files.. why do you want to remove the ctag? i think it is something to reconize i am correct it refers to a csom version..
May 24 2017 02:45 AM
jslinkfiles is the name of the document library.
Because i think ctag is making the problem.
i have copied the url with the ctag and pasted in the address bar and it did not work.
May 24 2017 04:45 AM
May 24 2017 08:14 AM
Does the copied URL work without the ctag?
I dont know if it will work but when i put it in the address bar without ctag , it works as its just the pure link.
yes, it was published.
This is not working for my organisations tenant.
I tried doing it in my personal tenant and it worked and becuase it worked, the url with the ctag is also not shown. So, i dont know if ctag is causing the issue but given the fact that it is appending to the item and putting it in address bar does not display the file makes me believe that.
What could be the difference between my personal tenant and my organisations tenant.
May 25 2017 01:54 AM
Is there a difference in licensing? as i could think of you may be having a developer tenant or be a admin which you may not be on the other tenant. it is still strange dow
May 25 2017 05:19 AM
May 30 2017 04:59 AM
So it worked when i created the list in the same location.
I have a subsite3 in
<serverlocation>/sites/sitecollection1/subsite1/subsite3 which hosts the list and the js file is hosted under
<serverlocation>/sites/sitecollection1/JSLinkFiles/PriorityColor.js
How do i put it in the js box for the list hosted under
<serverlocation>/sites/sitecollection1/subsite1/subsite3
if i use ~site it relaces current url.
thanks
Jun 01 2017 03:03 AM
For CSR development always use Chrome and the Extension Cisar, it does the templating for you and manages all the JSLinks for you, it is the best thing since sliced bread..
https://chrome.google.com/webstore/detail/cisar/nifbdojdggkboiifaklkamfpjcmgafpo?hl=en
Then replace that MSDN code for a Status color in a View with:
function statusColor( ctx, CurrentFieldSchema, CurrentItem, ListSchema ){ if (CurrentItem.hasOwnProperty(CurrentFieldSchema.Name + '.groupHeader')) { //do nothing when this Choice field is used in a Group By return CurrentItem[CurrentFieldSchema.Name]; } var _status=CurrentItem[ CurrentFieldSchema.Name ].Label, _html='<span style="color:{0}; font-weight:{1};">{2}</span>', _color='none', _weight='bold'; switch(_status){ case('Not Started'): case('OnHold'): _color='gold'; break; case('Active'): _color='green'; break; case('Completed'): _color='blue'; break; case('At Risk'): case('Cancelled'): case('Overdue'): _color='red'; break; default: _html='{2}'; } return( String.format(_html, _color, _weight, _status) ); }
Jun 01 2017 04:43 AM - edited Jun 01 2017 04:51 AM