I'm desperate and need your help on this script. I have a "multi line text" column named "Comments", and i added the following script into a script editor but it is not working for me. could you please help fix this?

<script type="text/javascript">
(function () {

 var linkFieldContext = {};
 linkFieldContext.Templates = {};
 linkFieldContext.Templates.Fields = { 
 "Comments": { "View": CommentRendering}


function ExpandDescription(a){

var small=a.parentNode.parentNode.getElementsByClassName('Small');
var full=a.parentNode.parentNode.getElementsByClassName('Full');


function CollapseDescription(a){

var small=a.parentNode.parentNode.getElementsByClassName('Small');
var full=a.parentNode.parentNode.getElementsByClassName('Full');


function CommentRendering(ctx)
 var htmlStr = "";
 var itemId = ctx.CurrentItem.ID;
 var itemDesc = ctx.CurrentItem.Comments;
var div = document.createElement("div");

div.innerHTML =itemDesc;

itemDesc = div.textContent || div.innerText || "";
 var itemDescSmall=itemDesc.substring(0, 50);
'}else{return ctx.CurrentItem.Comments;} return htmlStr;}
  • where did you add tag with "Small" and "Full" class name? Sep 10, 2019 at 9:56

1 Answer 1


Adding this script in script editor will not work.

You need to add it in JSLink property of List web part.

Try below steps:

How to set the JSLink property of your Web Part:

  1. Create JavaScript file with the code you are using.
  2. Click on Gear icon at top right corner.
  3. Edit the Page on which you have added list web part.
  4. Select the list web part and edit web part properties.
  5. Go to Miscellaneous --> JS Link property.
  6. Add the reference to newly create file in JSLink property.


  1. Save this JSLink.js file in same site and add path to miscellaneous--> as ~site/SiteAssets/JSLink.js. OR
  2. Save this JSLink.js file in same site collection and add path to miscellaneous--> as ~sitecollection/SiteAssets/JSLink.js.

For more details, check my answer given at Color Coding List Item by Web Part based on value

  • Hi Ganesh, thanks a lot for your help. the list view webpart is already linked to one JS Link file, as such i cannot link this one
    – T Zhang
    Sep 10, 2019 at 6:03
  • Ok, But you can merge both codes in order to make it work. Sep 10, 2019 at 6:11
  • Have you managed to get it working? Or you are facing any issue? Nov 20, 2019 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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