Status column to automatically update based on the expiry date

Sofie Gregory 0 Reputation points
2024-11-21T19:36:42.96+00:00

I am trying to set-up a SharePoint List and would like the status column to automatically update based on the expiry date. I am looking to have 3 options; Active, Expired, Needs Attention.

Expired (Red) = past the expiry date

Needs attention (Yellow)= 2 months prior to and up to the expiry date

Active (No colour) = Everything else

I do not have access to power flow so I am looking for JSON code.

Thank you in advance!

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,069 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yanli Jiang - MSFT 27,241 Reputation points Microsoft Vendor
    2024-11-22T08:00:55.19+00:00

    Hi @Sofie Gregory ,

    Welcome to Q&A forum!

    To set up a SharePoint List with a status column that automatically updates based on the expiry date, you can use JSON column formatting. Below is an example of how you can achieve the three status options (Active, Expired, Needs Attention) using JSON code.

    {
     "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "=if([$expirydate] < @now, 'Expired', if([$expirydate] > @now + 5184000000, 'Active', 'Needs attention'))",
    "style": {
    "background-color": "=if([$expirydate] < @now, 'red', if([$expirydate] > @now + 5184000000, ' ', 'yellow'))"
     }
    }
    
    

    And the result:

    User's image

    Good day!


    If the answer is helpful, please click "Accept as Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.