I would deeply appreciate any help. I have been staring at this code for days. I am trying to add a Script Editor web part above a list, and make the rows in the list change color according to how close today's date is to a suspense date (SuspenseDate column in the list.) I want to have a different column for items in these three circumstances: past due, 1 day before due, 2 days before due
This code does nothing, and I can't figure out why, despite hours of troubleshooting. My SuspenseDate column shows dates in standard format, with no time. (ex. 08/08/2023)
I have been banging my head against the wall on this for days. Please let me know if you have any ideas.
<script>
(function () {
'use strict';
var overrideCtx = {};
overrideCtx.Templates = {};
//OnPostRender call postRenderHandler function.
overrideCtx.OnPostRender = postRenderHandler;
// Register the template overrides.
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
function postRenderHandler(ctx) {
// get today's date
var today = new Date();
// zero out the time portion so we will only compare days
today.setHours(0,0,0,0);
var rows = ctx.ListData.Row;
for (var i = 0; i < rows.length; i++) {
// get the date set in your date YourDateField
var suspenseDate = new Date(rows[i]["SuspenseDate"]).toISOString();
var rowId = GenerateIIDForListItem(ctx, rows[i]);
var row = document.getElementById(rowId); // so we know which row to change
// get date 24 hours before suspense date
var suspense24 = new Date(suspenseDate);
suspense24.setDate(suspense24.getDate() - 1);
// get date 48 hours before suspense date
var suspense48 = new Date(suspenseDate);
suspense48.setDate(suspense48.getDate() - 2);
if (today > suspense24) {
row.style.backgroundColor = '#FF5733';
}
if (today == suspense24) {
row.style.backgroundColor = '#FFC300';
}
if (today == suspense48) {
row.style.backgroundColor = '#DAF7A6';
}
}
}
</script>
var suspenseDate = new Date(rows[i]["SuspenseDate"]).toISOString();
. You can get the internal name of list column by following: ganeshsanapblogs.wordpress.com/2023/04/17/…. Let me know if it is still not working.