Column Formatting JSON

MichaelHan-MSFT 18,016 Reputation points
2020-11-04T01:32:43.55+00:00

Dear all,

I am need of some help with JSON code writing for sharepoint lists.

I have tried multiple different variations but I can't seem to get

• Green box if list date is + 90 days →

• Yellow if list date is within 90 days

• Red if it is expired.

I am aware using designer you can have the traffic light for if it is (after today green), (if it is today yellow) and if (it is before today red).

If some can help by posting Json code to implement into list that would be very helpful.

Thank you.

Source link from TechNet

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,628 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jerry Xu-MSFT 7,921 Reputation points
    2020-11-04T06:23:49.46+00:00

    Hi,

    Please have a try with the JSON below, it works in my end.

    {  
       "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
       "elmType": "div",  
       "attributes": {  
         "class": "=if(@currentField <=@now ,'sp-field-severity--severeWarning',if(@currentField <=(@now+7776000000)  ,'sp-field-severity--warning','sp-field-severity--good'))"  
       },  
       "children": [  
         {  
           "elmType": "span",  
           "style": {  
             "display": "inline-block",  
             "padding": "0 4px"  
           },  
           "attributes": {  
             "iconName": "=if(@currentField <=@now ,'ErrorBadge',if(@currentField <=(@now+7776000000)  ,'Error','Forward'))"  
           }  
         },  
         {  
           "elmType": "span",  
           "txtContent": "@currentField"  
         }  
       ]  
     }  
    

    37328-image.png

    Update :

    {  
       "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
       "elmType": "div",  
       "txtContent": "@currentField",  
       "style": {  
          "color": "=if(@currentField <=@now ,'#ff0000',if(@currentField <=(@now+7776000000)  ,'#F4D03F','#58FF33'))"  
            
       }  
    }  
    

    37691-image.png

    {  
       "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
       "elmType": "div",  
       "txtContent": "@currentField",  
       "style": {  
          "background-color": "=if(@currentField <=@now ,'#ff0000',if(@currentField <=(@now+7776000000)  ,'#F4D03F','#58FF33'))"  
            
       }  
    }  
    

    37692-image.png


    If the answer is helpful, please click Accept Answer and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. needhelpwithJSON 1 Reputation point
    2020-11-04T15:00:34.663+00:00

    Dear JerryXu-MSFT,

    Thank you for the JSON code yes it works well the only issue being implementing it onto nonwhite background lists and libraries as the colours of the sections don't work as well any chance of a JSON code with the same function but changeable HEX colour code sections?

    Thank you for the help and time.

    0 comments No comments