question

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT asked needhelpwithJSON-6781 commented

Column Formatting JSON

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


office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JerryXu-MSFT avatar image
0 Votes"
JerryXu-MSFT answered needhelpwithJSON-6781 commented

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.



image.png (4.0 KiB)
image.png (5.0 KiB)
image.png (5.8 KiB)
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

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 Votes 0 ·
JerryXu-MSFT avatar image JerryXu-MSFT needhelpwithJSON-4190 ·

Hi, @needhelpwithJSON-4190 ,

I updated with new JSON, choose the one you need.

0 Votes 0 ·
JerryXu-MSFT avatar image JerryXu-MSFT needhelpwithJSON-4190 ·

Hi, @needhelpwithJSON-4190 ,

Have you tried with the new JSON? Does it work for you?

0 Votes 0 ·

Dear Jerry Xu-MSFT,

Yes the second version is the one I used and changed the yellow and green only the red I couldn't figure out how but that is due to a lack of knowledge on my part.

the JSON I used ↓ {
"$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) ,'#96882b','#458b50'))"

 }

}

THANK YOU for your help

0 Votes 0 ·
Show more comments

Good Afternoon Jerry Xu-MSFT,

i have been using this JSON which you helped with and it has been working great the only issue being the background colour when the field is empty. 57702-expiry-date.png
can you assist how do I change it that when they expire its red 90 days before expiry yellow, green when it's not in 90 days before expiry and background colour when there is no date input.
Any help would be appreciated.

Thank you.

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


0 Votes 0 ·
expiry-date.png (6.3 KiB)
needhelpwithJSON-4190 avatar image
0 Votes"
needhelpwithJSON-4190 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.