Forum Discussion
Joseph_Butler
Mar 12, 2021Copper Contributor
Color Code SharePoint List cell based on Due Date and Status columns
I am using the Javascript (at the bottom) on my SP 2013 site to color code a Due Date field. This code as written, does just that. However, if the Status column for the list item is set to Co...
- Mar 15, 2021
Not sure if this is exactly what you need. You should be able to modify where this code is located.
Before the first line of code in your, add the following.
if (!ctx.CurrentItem.DueDate || ctx.CurrentItem.Status.toLowerCase() === "completed") return;
This checks if the DueDate exists and then if the Status = Complete. If either condition is true, the function exits (return;)
If this works for you, please mark this response as the answer. Thanks!
Don Kirkham
Mar 15, 2021MVP
Not sure if this is exactly what you need. You should be able to modify where this code is located.
Before the first line of code in your, add the following.
if (!ctx.CurrentItem.DueDate || ctx.CurrentItem.Status.toLowerCase() === "completed") return;
This checks if the DueDate exists and then if the Status = Complete. If either condition is true, the function exits (return;)
If this works for you, please mark this response as the answer. Thanks!
- Joseph_ButlerMar 15, 2021Copper ContributorThe code provided removes the date from the Due Date field., so I updated it with the color:
if (!ctx.CurrentItem.DueDate || ctx.CurrentItem.Status.toLowerCase() === "completed")
return "<div style='background-color:white;color:black'>" + ctx.CurrentItem.DueDate + "</div>";- Don KirkhamMar 15, 2021MVPSounds good. That's why I said in my answer that I wasn't exactly sure where you needed the code to go. The important part was the comparison piece and I was counting on you to adjust as needed.
Glad you got it working!- Sarip2009Apr 26, 2021Copper ContributorWorked for me for formatting
- RobElliottMar 15, 2021Silver Contributor===? never seen that before.
- Don KirkhamMar 15, 2021MVPThis explains the difference:
https://howtodoinjava.com/javascript/javascript-equality-vs-identity-operators/
They both work in this case, but === removed the implicit typing step since we know both values are strings.