Forum Discussion

oskarkuus's avatar
oskarkuus
Brass Contributor
Oct 18, 2023

120 days before a date format row red backgorund and white text

Hi

 

How can i format a sharepoint column so the whole row turns red and text is white.

I want to get a warning with a red row 120 days before the value in "startdate" is equal to todays date

 

How do i change this?

  • luis-ribeiro's avatar
    luis-ribeiro
    Brass Contributor

    Hi oskarkuus 

     

    this should do the trick. In the sample the date field name is mydate.

     

    {
    "additionalRowClass": "=if(toString([$mydate]) == '', '', if(([$mydate]>@now), '', if((@now-[$mydate]) <= 10368000000, 'sp-css-backgroundColor-BgRed sp-field-fontSizeSmall sp-css-color-WhiteText', '')))"
    }
     
    10368000000 = 120 days converted to miliseconds

    Regards



  • oskarkuus Unfortunately, I did not understand this condition clearly: get a warning with a red row 120 days before the value in "startdate" is equal to todays date

     

    However, you can easily achieve it using SharePoint JSON view formatting. You will have to use the JSON like:

     

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
      "additionalRowClass": "=if(Number([$StartDate]) == 0, '', if(addDays([$StartDate],-120) <= @now, 'sp-css-backgroundColor-BgRed sp-css-color-WhiteText', ''))"
    }

     

    You can change the operator (<=) in above JSON as per your requirements.

     

    Instead of StartDate, use internal name of your SharePoint list date column. You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online? 

     

    Here I have used Number([$StartDate]) == 0 to check if SharePoint date column is blank or not. You can find other ways to check if SharePoint date & time column is empty or not at:  SharePoint JSON formatting: Check if date & time column is blank/empty


    Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

    • oskarkuus's avatar
      oskarkuus
      Brass Contributor

      ganeshsanap 

      Thanks for your reply, but i can not get this to work.

       

      If i put in this code:

      {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
      "additionalRowClass": "=if(Number([$Slutdatum]) == 0, '', if(addDays([$Slutdatum],-120) <= @now, 'sp-css-backgroundColor-BgRed sp-css-color-WhiteText', ''))"
      }

       

      All text becomes white no matter what the date is set to.

      And the background never turns red no matter what the date is set to.

       

      My column name is "Slutdatum".

Resources