0

New to the whole JSON code within SharePoint lists, hit a brick wall and having no luck with research.

I require 2 conditional formatting writing into the cod but am not having much look.

First - if the 'Re-Certification Date'(which is a calculated column) is Over 1035+ days = Green 1035 days = Orange 0 Days = Red

To do so I have the below JSON Code wrote:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if(@currentField <= addDays(@now,0), 'red', if(@currentField <= addDays(@now,60), 'orange', if(@currentField > addDays([$Certificationdate],1095), 'green','green',)",
    "color": "=if(@currentField <= addDays(@now,0), 'white', 'white')",
    "padding-left": "10px"
  }
}

Is this correct and the simplest way of writing it?

Question 2 - How do i add a second conditional formatting JSON code to the same column so that if the 'Status' column = 'Left the Company' the cell is filled black with black text?? i have tried a few ways and had no success.

Or is it possible to remove the date from the calculated column based on anothers status??

Any help is greatly appreciated!!!

enter image description here

1 Answer 1

0

Add a second condition to the background-color and color properties to check if the "Status" column equals "Left the Company". Here is the code snippet:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if([$Status] == 'Left the Company', 'black', if(@currentField <= addDays(@now,0), 'red', if(@currentField <= addDays(@now,1035), 'orange', if(@currentField > addDays([$Certificationdate],1035), 'green','green')))",
    "color": "=if([$Status] == 'Left the Company', 'black', if(@currentField <= addDays(@now,0), 'white', 'white'))",
    "padding-left": "10px"
  }
}
2
  • 1
    Life saver, thank you very much!
    – JB94
    Commented Feb 22 at 8:11
  • @JB94 Im happy this worked for you, please mark it as the solution so that others may find it easier. Commented Feb 26 at 15:16

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.