folks. We're looking for a code-block to copy/paste for a hopefully simple color-coding-by-date situation in SharePoint modern/Online: a document expiration date.

We want to set a condition on a library's Next Review column (date format) where the item will turn *Yellow if the doc's Next Review date is less than 90 days away *Red if the doc's Next Review date is less than 10 days away or already past (i.e., expired)

We've determined that this will require some sort of conditional formatting, probably using the "JSON" coding. We have no programmers; JSON is a complete black box to us, so we'll be blindly copy/pasting whatever chunk of code we find.

And because SP Online's interface is confusion, we'll need instructions on what values in the chunk of code we need to tweak, as well as instructions on exactly WHERE to paste this code.

You see, a SharePoint Online column doesn't have a single Format box. When you click the column heading and go to Column Settings > Format this Column, you get two tabs: Format View and Format Columns.

The Format View tab has Choose Layout and a code box, while the Format Columns tab has Edit Styles, (conditional formatting) Manage Rules, and Advanced Mode. Unfortunately, there's no online help or documentation for SharePoint Online, so we don't know where to paste any example code that we find. Suggestions appreciated.

  • Check this documentation for column JSON formatting in SP online. Oct 14, 2021 at 18:09
  • I did; couldn't make any sense out of it. Way too complicated. As noted, none of us are programmers, and the terms and concepts are far beyond us. Oct 18, 2021 at 12:39

1 Answer 1


Please use the below JSON code:

    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "@currentField",
    "style": {
       "background-color": "=if(Number(@currentField) == 0, '', if(@currentField <= @now + 864000000, 'red', if(@currentField <= @now + 7776000000, 'yellow', '')))"

enter image description here

enter image description here

enter image description here

enter image description here

  • That does it, thanks very much! . I'm curious: It looks like both the Format Columns and Format View tab have this "Advanced Mode" option for pasting code. What's the difference? What would be the effect of putting the code on the Format View tab instead? Oct 18, 2021 at 12:23
  • "Format View" can be used to format the entire list view (all columns) while Format Columns only formats the individual list column. Oct 18, 2021 at 12:55
  • Hi Brian Curtis. The Format view works on the current view, while the Format columns only works on the current column. Oct 20, 2021 at 9:46
  • View formatting: docs.microsoft.com/en-us/sharepoint/dev/… Column formatting: docs.microsoft.com/en-us/sharepoint/dev/… Oct 20, 2021 at 9:47
  • Hi Brian Curtis. I'm glad to hear that your problem has been solved. If the answer is helpful to you, you can accept it as answer. The behavior will help others who meet the similar issue in the future quickly find the correct answer. Oct 20, 2021 at 9:48

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.