0

i have a list with a Deadline date field, i want to add a DaysToDeadLine field to show how many days are left before the DL. I read that there's issues with the today() function in sharepoint so i'm using the json formatting options, it works for giving me the days but it doesn't work the formatting option.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "debugMode": true,
  "txtContent": "=floor((Number([$DeadLine])-Number(@now))/(1000*60*60*24))",
  "attributes": {
    "class": "=if(@currentField > 51, 'sp-field-severity--good', if(@currentField <= 50 && @currentField >= 11, 'sp-field-severity--warning', if(@currentField < 10, 'sp-field-severity--severeWarning', '')) + ' ms-fontColor-neutralSecondary'"
  }
}

I'd like to make a conditional check:

  • red background if the result of the calculus it's <10
  • orange background if the result is >= 11 and <= 50
  • green background if the result is >51

what am i doing wrong? seems like the currentfield value is not set as the txtContent, how eventually fix this?

2
  • i fixed the code repeating the full expression instead of currentfield, is there a cleaner way?
    – antonioa7
    Commented Mar 10, 2022 at 16:44
  • You can convert the number of days to milliseconds & then use simpler comparison conditions in JSON. For more information, check my answer given here. Commented Mar 10, 2022 at 17:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.