1

Actually I got a code which works really nice when I use it in a list depending on a normal field. When I try to Highlight the rows considering the Workflow Status it doesn´t work, Any advises? I paste the code I have right now.

I already tried to Name the Workflow "Status" but it still doesn´t work.

Thanks in regard.

OnPostRender: function(ctx) {

   var statusColors =  {
      'In Progress' : '#FFF1AD',  
      'Approved' : '#FFD800',
      'Rejected' : '#01DF3A' 
   };

   var rows = ctx.ListData.Row;
   for (var i=0;i<rows.length;i++)
   {
      var status = rows[i]["Status"];
      var rowId = GenerateIIDForListItem(ctx, rows[i]);
      var row = document.getElementById(rowId); 
      row.style.backgroundColor = statusColors[status];
   }
 }
  • 3
    Please try to access "_ModerationStatus" field instead of "Status" field. – Dikesh Gandhi Mar 8 '17 at 11:28
  • 1
    If that doesn't work (could be some Microsoft magic with that Field, as it also is not available in Calculated Columns) You can do it the oldfashioned way..Your code already has the rowId, so you can walk the DOM TR tow to get the TD where WorkflowStatus is displayed, get the innerText and take it from there. – Danny '365CSI' Engelman Mar 8 '17 at 14:28
1

Found a blogpost that does exactly what you need. Changed it and added it to reflect your code.

Changed In Progress to Pending as that's what SharePoint call it while waiting for an approval/reject.

SharePoint 2013 Client Side Rendering: List Views

SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
  OnPostRender: function(ctx) {
    var rows = ctx.ListData.Row;
    for (var i=0;i<rows.length;i++)
    {
      var isApproved = rows[i]["_ModerationStatus"] == "Approved";
      if (isApproved)
      {
        var rowElementId = GenerateIIDForListItem(ctx, rows[i]);
        var tr = document.getElementById(rowElementId);
        tr.style.backgroundColor = "#FFD800";
      }
      var isPending = rows[i]["_ModerationStatus"] == "Pending";
      if (isPending)
      {
        var rowElementId = GenerateIIDForListItem(ctx, rows[i]);
        var tr = document.getElementById(rowElementId);
        tr.style.backgroundColor = "#FFF1AD";
      }
      var isRejected = rows[i]["_ModerationStatus"] == "Rejected";
      if (isRejected)
      {
        var rowElementId = GenerateIIDForListItem(ctx, rows[i]);
        var tr = document.getElementById(rowElementId);
        tr.style.backgroundColor = "#01DF3A";
      }
    }
  }
});

Gives me this result.

enter image description here

  • Sadly it doesn´t work. I think that somehow the Code is not reaching the values with a Workflow status field in the same way it does it with a normal field. – Jorge Nitales Mar 8 '17 at 10:56
  • Is your workflow status column named status? Try "_ModerationStatus" instead of "Status". See if you got better luck with that field. It might be that the workflow column got an internal name that you need to use. The value stored in the status column is a lookup as well, so use F12 developer tool and see if you can see how the value is stored. Should be ID;#Status – Christoffer Mar 8 '17 at 11:29
  • @JorgeNitales I think that Dikesh Ghandi got the right answer before i did. :) – Christoffer Mar 8 '17 at 11:44
  • As Dikesh Ghandi said I tried with "_ModerationStatus". I tried with both values (Status and Value). Also I found the ID as "WorkflowInstanceID" in the Developer tool, which looks like the internal ID but it doesn´t work either. I really missed SharePoint! – Jorge Nitales Mar 8 '17 at 13:22
  • @JorgeNitales Think it should work now. – Christoffer Mar 8 '17 at 14:38

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.